2018-07-23 17:32:36 +08:00
|
|
|
|
# 敬告:本脚本仅作测试交流使用,详细操作说明请参阅docs/op/change_ip_allinone.md
|
2018-05-24 16:35:21 +08:00
|
|
|
|
# 此脚本仅用于allinone部署情况下,需要修改host ip地址使用(比如,虚机装完allinone部署,克隆或者复制分享给别人测试使用)
|
|
|
|
|
#
|
|
|
|
|
# ------- 前提 :一个运行正常的allinone部署在虚机,关机后复制给别人使用,新虚机开机后如果需要修改IP,请执行如下步骤
|
|
|
|
|
# 1. 修改ansible hosts文件:sed -i 's/$OLD_IP/$NEW_IP/g' /etc/ansible/hosts
|
|
|
|
|
# 2. 配置ssh免密码登陆:ssh-copy-id $NEW_IP 按提示完成
|
|
|
|
|
# 3. 检查下修改是否成功,并且能够成功执行 ansible all -m ping
|
2019-05-18 16:48:58 +08:00
|
|
|
|
# 4. 运行本脚本 ansible-playbook /etc/ansible/tools/change_ip_aio.yml
|
2018-05-24 16:35:21 +08:00
|
|
|
|
|
|
|
|
|
- hosts: deploy # hosts 角色无所谓,反正allinone所有角色都是同个ip
|
|
|
|
|
tasks:
|
|
|
|
|
- name: 删除一些证书和配置,后面会以新IP重新生成
|
|
|
|
|
file: name={{ item }} state=absent
|
|
|
|
|
with_items:
|
|
|
|
|
- "/etc/etcd/ssl/etcd.pem" # 删除etcd证书
|
|
|
|
|
- "/etc/kubernetes/ssl/kubernetes.pem" # 删除旧master证书
|
|
|
|
|
- "/etc/kubernetes/kubelet.kubeconfig" # 删除旧kubelet配置文件
|
|
|
|
|
|
|
|
|
|
- hosts: deploy
|
|
|
|
|
roles:
|
|
|
|
|
- deploy
|
|
|
|
|
- etcd
|
|
|
|
|
- kube-master
|
|
|
|
|
- kube-node
|
|
|
|
|
|
|
|
|
|
- hosts: deploy
|
|
|
|
|
tasks:
|
|
|
|
|
- name: 删除老IP地址的node
|
2018-06-09 22:19:20 +08:00
|
|
|
|
shell: "{{ bin_dir }}/kubectl get node |grep -v '{{ inventory_hostname }}'|awk '{print $1}' |xargs {{ bin_dir }}/kubectl delete node"
|
2018-05-24 16:35:21 +08:00
|
|
|
|
ignore_errors: true
|
|
|
|
|
|
|
|
|
|
- name: 删除原network插件部署
|
|
|
|
|
shell: "{{ bin_dir }}/kubectl delete -f /opt/kube/kube-system/{{ CLUSTER_NETWORK }}/ || \
|
|
|
|
|
{{ bin_dir }}/kubectl delete -f /root/local/kube-system/{{ CLUSTER_NETWORK }}/"
|
|
|
|
|
ignore_errors: true
|
|
|
|
|
|
|
|
|
|
- hosts: deploy
|
|
|
|
|
roles:
|
|
|
|
|
- { role: calico, when: "CLUSTER_NETWORK == 'calico'" }
|
2018-08-05 16:12:32 +08:00
|
|
|
|
- { role: cilium, when: "CLUSTER_NETWORK == 'cilium'" }
|
2018-05-24 16:35:21 +08:00
|
|
|
|
- { role: flannel, when: "CLUSTER_NETWORK == 'flannel'" }
|
2018-06-14 09:39:47 +08:00
|
|
|
|
- { role: kube-router, when: "CLUSTER_NETWORK == 'kube-router'" }
|