2018-07-23 17:32:36 +08:00
|
|
|
|
# 重置k8s pod网络脚本,使用请仔细阅读 docs/op/change_k8s_network.md
|
2018-06-26 22:00:37 +08:00
|
|
|
|
- hosts:
|
|
|
|
|
- kube-master
|
|
|
|
|
- new-master
|
|
|
|
|
- kube-node
|
|
|
|
|
- new-node
|
|
|
|
|
tasks:
|
|
|
|
|
- name: 获取所有已经创建的POD信息
|
|
|
|
|
command: "{{ bin_dir }}/kubectl get daemonset -n kube-system"
|
|
|
|
|
register: pod_info
|
|
|
|
|
run_once: true
|
|
|
|
|
|
|
|
|
|
- name: 删除原network插件calico部署
|
|
|
|
|
shell: "{{ bin_dir }}/kubectl delete -f /opt/kube/kube-system/calico/ || \
|
|
|
|
|
{{ bin_dir }}/kubectl delete -f /root/local/kube-system/calico/"
|
|
|
|
|
ignore_errors: true
|
|
|
|
|
run_once: true
|
|
|
|
|
when: '"calico" in pod_info.stdout'
|
|
|
|
|
|
2018-08-11 22:37:57 +08:00
|
|
|
|
- name: 删除原network插件cilium部署
|
|
|
|
|
shell: "{{ bin_dir }}/kubectl delete -f /opt/kube/kube-system/cilium/ || \
|
|
|
|
|
{{ bin_dir }}/kubectl delete -f /root/local/kube-system/cilium/"
|
|
|
|
|
ignore_errors: true
|
|
|
|
|
run_once: true
|
|
|
|
|
when: '"cilium" in pod_info.stdout'
|
|
|
|
|
|
2018-06-26 22:00:37 +08:00
|
|
|
|
- name: 删除原network插件flannel部署
|
|
|
|
|
shell: "{{ bin_dir }}/kubectl delete -f /opt/kube/kube-system/flannel/ || \
|
|
|
|
|
{{ bin_dir }}/kubectl delete -f /root/local/kube-system/flannel/"
|
|
|
|
|
ignore_errors: true
|
|
|
|
|
run_once: true
|
|
|
|
|
when: '"flannel" in pod_info.stdout'
|
|
|
|
|
|
|
|
|
|
- name: 删除原network插件kube-router部署
|
|
|
|
|
shell: "{{ bin_dir }}/kubectl delete -f /opt/kube/kube-system/kube-router/ || \
|
|
|
|
|
{{ bin_dir }}/kubectl delete -f /root/local/kube-system/kube-router/"
|
|
|
|
|
ignore_errors: true
|
|
|
|
|
run_once: true
|
|
|
|
|
when: '"kube-router" in pod_info.stdout'
|
|
|
|
|
|
|
|
|
|
- name: 清理kube-router相关
|
|
|
|
|
shell: "{{ bin_dir }}/docker run --privileged --net=host cloudnativelabs/kube-router --cleanup-config"
|
|
|
|
|
ignore_errors: true
|
|
|
|
|
when: '"kube-router" in pod_info.stdout'
|
2018-07-08 11:41:40 +08:00
|
|
|
|
|
|
|
|
|
- name: 停止 kube-node 相关服务
|
|
|
|
|
service: name={{ item }} state=stopped
|
|
|
|
|
with_items:
|
|
|
|
|
- kubelet
|
|
|
|
|
- kube-proxy
|
|
|
|
|
ignore_errors: true
|
|
|
|
|
|
|
|
|
|
- name: 清理calico残留路由
|
|
|
|
|
shell: "for rt in `ip route|grep bird|sed 's/blackhole//'|awk '{print $1}'`;do ip route del $rt;done;"
|
|
|
|
|
when: '"calico" in pod_info.stdout'
|
|
|
|
|
ignore_errors: true
|
|
|
|
|
|
|
|
|
|
- name: 清理 kube-proxy产生的iptables规则
|
|
|
|
|
shell: "{{ bin_dir }}/kube-proxy --cleanup"
|
2018-06-26 22:00:37 +08:00
|
|
|
|
ignore_errors: true
|
2018-07-08 11:41:40 +08:00
|
|
|
|
|
2018-06-26 22:00:37 +08:00
|
|
|
|
- name: 清理目录和文件
|
|
|
|
|
file: name={{ item }} state=absent
|
|
|
|
|
with_items:
|
|
|
|
|
- "/etc/cni/"
|
|
|
|
|
- "/run/flannel/"
|
|
|
|
|
- "/etc/calico/"
|
|
|
|
|
- "/var/run/calico/"
|
2018-08-11 22:37:57 +08:00
|
|
|
|
- "/var/lib/calico/"
|
2018-06-26 22:00:37 +08:00
|
|
|
|
- "/var/log/calico/"
|
2018-08-11 22:37:57 +08:00
|
|
|
|
- "/etc/cilium/"
|
|
|
|
|
- "/var/run/cilium/"
|
|
|
|
|
- "/sys/fs/bpf/tc/"
|
2018-06-26 22:00:37 +08:00
|
|
|
|
- "/var/lib/cni/"
|
|
|
|
|
- "/var/lib/kube-router/"
|
|
|
|
|
- "/opt/kube/kube-system/"
|
|
|
|
|
|
|
|
|
|
- name: 清理网络
|
|
|
|
|
shell: "ip link del tunl0; \
|
|
|
|
|
ip link del flannel.1; \
|
|
|
|
|
ip link del cni0; \
|
|
|
|
|
ip link del mynet0; \
|
|
|
|
|
ip link del kube-bridge; \
|
|
|
|
|
ip link del dummy0; \
|
2018-08-11 22:37:57 +08:00
|
|
|
|
ip link del kube-ipvs0; \
|
|
|
|
|
ip link del cilium_net; \
|
|
|
|
|
ip link del cilium_vxlan; \
|
2018-06-26 22:00:37 +08:00
|
|
|
|
systemctl restart networking; \
|
|
|
|
|
systemctl restart network"
|
|
|
|
|
ignore_errors: true
|
|
|
|
|
|
2018-07-08 11:41:40 +08:00
|
|
|
|
- name: 开启 kube-node 相关服务
|
|
|
|
|
service: name={{ item }} state=started enabled=yes
|
|
|
|
|
with_items:
|
|
|
|
|
- kubelet
|
|
|
|
|
- kube-proxy
|
2018-06-26 22:00:37 +08:00
|
|
|
|
ignore_errors: true
|
2018-07-20 17:24:17 +08:00
|
|
|
|
|
|
|
|
|
- hosts:
|
|
|
|
|
- lb
|
|
|
|
|
tasks:
|
|
|
|
|
- name: 重启lb的keepalived服务
|
|
|
|
|
service: name=keepalived state=restarted
|
2018-08-11 22:37:57 +08:00
|
|
|
|
|
|
|
|
|
- name: 轮询等待apiserver服务恢复
|
|
|
|
|
command: "{{ bin_dir }}/kubectl get node"
|
|
|
|
|
register: result
|
|
|
|
|
until: result.rc == 0
|
|
|
|
|
retries: 5
|
|
|
|
|
delay: 6
|
|
|
|
|
delegate_to: "{{ groups.deploy[0] }}"
|
|
|
|
|
run_once: true
|
2018-07-08 11:41:40 +08:00
|
|
|
|
|
|
|
|
|
- hosts:
|
|
|
|
|
- kube-master
|
|
|
|
|
- new-master
|
|
|
|
|
- kube-node
|
|
|
|
|
- new-node
|
|
|
|
|
# 安装新的网络插件
|
|
|
|
|
roles:
|
|
|
|
|
- { role: calico, when: "CLUSTER_NETWORK == 'calico'" }
|
2018-08-05 16:12:32 +08:00
|
|
|
|
- { role: cilium, when: "CLUSTER_NETWORK == 'cilium'" }
|
2018-07-08 11:41:40 +08:00
|
|
|
|
- { role: flannel, when: "CLUSTER_NETWORK == 'flannel'" }
|
|
|
|
|
- { role: kube-router, when: "CLUSTER_NETWORK == 'kube-router'" }
|
2018-06-26 22:00:37 +08:00
|
|
|
|
|
2018-07-08 11:41:40 +08:00
|
|
|
|
- hosts: deploy
|
|
|
|
|
tasks:
|
2018-06-26 22:00:37 +08:00
|
|
|
|
# 删除所有运行pod,由controller自动重建
|
|
|
|
|
- name: 重启所有pod
|
|
|
|
|
shell: "for NS in $({{ bin_dir }}/kubectl get ns|awk 'NR>1{print $1}'); \
|
2018-07-08 11:41:40 +08:00
|
|
|
|
do {{ bin_dir }}/kubectl delete pod --all -n $NS; done;"
|
2018-06-26 22:00:37 +08:00
|
|
|
|
ignore_errors: true
|
|
|
|
|
run_once: true
|
2018-07-08 11:41:40 +08:00
|
|
|
|
|