kubeasz/tools/change_ip_aio.yml

42 lines
1.9 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

# 敬告本脚本仅作测试交流使用详细操作说明请参阅docs/op/change_ip_allinone.md
# 此脚本仅用于allinone部署情况下需要修改host ip地址使用比如虚机装完allinone部署克隆或者复制分享给别人测试使用
#
# ------- 前提 一个运行正常的allinone部署在虚机关机后复制给别人使用新虚机开机后如果需要修改IP请执行如下步骤
# 0. 拉取最新项目代码git pull origin master
# 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
- 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
shell: "{{ bin_dir }}/kubectl get node |grep -v '{{ inventory_hostname }}'|awk '{print $1}' |xargs {{ bin_dir }}/kubectl delete node"
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'" }
- { role: flannel, when: "CLUSTER_NETWORK == 'flannel'" }
- { role: kube-router, when: "CLUSTER_NETWORK == 'kube-router'" }