# 敬告:本脚本仅作测试交流使用 # 此脚本仅用于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'" }