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
|
|
|
|
|
2019-06-01 22:16:14 +08:00
|
|
|
|
- hosts: kube-master # hosts 角色无所谓,反正allinone所有角色都是同个ip
|
2018-05-24 16:35:21 +08:00
|
|
|
|
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配置文件
|
|
|
|
|
|
2019-06-01 22:16:14 +08:00
|
|
|
|
- hosts: kube-master
|
2018-05-24 16:35:21 +08:00
|
|
|
|
roles:
|
|
|
|
|
- deploy
|
|
|
|
|
- etcd
|
|
|
|
|
- kube-master
|
|
|
|
|
- kube-node
|
|
|
|
|
|
2019-06-01 22:16:14 +08:00
|
|
|
|
- hosts: kube-master
|
2018-05-24 16:35:21 +08:00
|
|
|
|
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插件部署
|
2019-06-01 22:16:14 +08:00
|
|
|
|
shell: "{{ bin_dir }}/kubectl delete -f /opt/kube/kube-system/{{ CLUSTER_NETWORK }}.yaml || \
|
|
|
|
|
{{ bin_dir }}/kubectl delete -f /opt/kube/kube-ovn/"
|
2018-05-24 16:35:21 +08:00
|
|
|
|
ignore_errors: true
|
|
|
|
|
|
2019-06-01 22:16:14 +08:00
|
|
|
|
- hosts: kube-master
|
2018-05-24 16:35:21 +08:00
|
|
|
|
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'" }
|
2019-05-22 14:31:29 +08:00
|
|
|
|
- { role: kube-ovn, when: "CLUSTER_NETWORK == 'kube-ovn'" }
|