From 254f6528b9eef2d931fe60db179b47186ec539b1 Mon Sep 17 00:00:00 2001 From: gjmzj Date: Sat, 1 Jun 2019 22:16:14 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4addetcd/addnode/addmaster?= =?UTF-8?q?=E7=AD=89=E8=84=9A=E6=9C=AC2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/guide/chrony.md | 2 +- roles/kube-router/tasks/main.yml | 4 ++-- tools/{19.addetcd.yml => 01.addetcd.yml} | 0 tools/{20.addnode.yml => 02.addnode.yml} | 0 tools/{21.addmaster.yml => 03.addmaster.yml} | 0 .../{remove_etcd_node.yml => 11.deletcd.yml} | 6 ++--- tools/change_ip_aio.yml | 12 +++++----- tools/change_k8s_network.yml | 22 ++----------------- tools/easzctl | 8 +++---- 9 files changed, 17 insertions(+), 37 deletions(-) rename tools/{19.addetcd.yml => 01.addetcd.yml} (100%) rename tools/{20.addnode.yml => 02.addnode.yml} (100%) rename tools/{21.addmaster.yml => 03.addmaster.yml} (100%) rename tools/{remove_etcd_node.yml => 11.deletcd.yml} (91%) diff --git a/docs/guide/chrony.md b/docs/guide/chrony.md index 684cdc2..ae32473 100644 --- a/docs/guide/chrony.md +++ b/docs/guide/chrony.md @@ -35,7 +35,7 @@ server {{ groups.deploy[0] }} iburst - 修改 ansible hosts 文件,在 `deploy` 节点配置 `NTP_ENABLED=yes` (默认: no) - [可选] 修改 roles/chrony/var/main.yml 中的变量定义,关于文件 roles/chrony/var/main.yml 的由来请看[这里](../setup/config_guide.md) -对于新集群或者新节点,`chrony` 的安装配置已经集成到 `90.setup.yml` `01.prepare.yml` `20.addnode.yml` `21.addmaster.yml` 等脚本中;对于已运行中的集群请执行如下命令进行安装: +对于新集群或者新节点,`chrony` 的安装配置已经集成到脚本中;对于已运行中的集群请执行如下命令进行安装: `ansible-playbook /etc/ansible/roles/chrony/chrony.yml ` diff --git a/roles/kube-router/tasks/main.yml b/roles/kube-router/tasks/main.yml index e4fa444..07d9dbd 100644 --- a/roles/kube-router/tasks/main.yml +++ b/roles/kube-router/tasks/main.yml @@ -6,7 +6,7 @@ - /opt/kube/kube-system - name: 准备配置 kube-router DaemonSet (without IPVS) - template: src=kuberouter.yaml.j2 dest=/opt/kube/kube-system/kuberouter.yaml + template: src=kuberouter.yaml.j2 dest=/opt/kube/kube-system/kube-router.yaml - name: 下载cni plugins copy: src={{ base_dir }}/bin/{{ item }} dest={{ bin_dir }}/{{ item }} mode=0755 @@ -58,7 +58,7 @@ # 只需单节点执行一次 - name: 运行 kube-router DaemonSet - shell: "{{ bin_dir }}/kubectl apply -f /opt/kube/kube-system/kuberouter.yaml" + shell: "{{ bin_dir }}/kubectl apply -f /opt/kube/kube-system/kube-router.yaml" run_once: true # 删除原有cni配置 diff --git a/tools/19.addetcd.yml b/tools/01.addetcd.yml similarity index 100% rename from tools/19.addetcd.yml rename to tools/01.addetcd.yml diff --git a/tools/20.addnode.yml b/tools/02.addnode.yml similarity index 100% rename from tools/20.addnode.yml rename to tools/02.addnode.yml diff --git a/tools/21.addmaster.yml b/tools/03.addmaster.yml similarity index 100% rename from tools/21.addmaster.yml rename to tools/03.addmaster.yml diff --git a/tools/remove_etcd_node.yml b/tools/11.deletcd.yml similarity index 91% rename from tools/remove_etcd_node.yml rename to tools/11.deletcd.yml index b27a2e0..fca25e8 100644 --- a/tools/remove_etcd_node.yml +++ b/tools/11.deletcd.yml @@ -1,5 +1,5 @@ # remove a etcd member -- hosts: deploy +- hosts: localhost vars_prompt: - name: "ETCD_TO_DEL" prompt: "which etcd node is about to be deleted?(e.g 192.168.1.1)" @@ -30,7 +30,6 @@ dest: "{{ base_dir }}/hosts" state: absent regexp: '{{ ETCD_NAME.stdout }}' - connection: local when: "ETCD_NAME.stdout != ''" - name: delete a etcd member @@ -44,8 +43,7 @@ when: "ETCD_ID.stdout != ''" - name: reconfig and restart the etcd cluster - shell: "ansible-playbook /etc/ansible/02.etcd.yml > /tmp/ansible-playbook.log 2>&1" - connection: local + shell: "ansible-playbook {{ base_dir }}/02.etcd.yml > /tmp/ansible-playbook.log 2>&1" when: "ETCD_ID.stdout != ''" run_once: true # 满足条件才进行删除 diff --git a/tools/change_ip_aio.yml b/tools/change_ip_aio.yml index f36a6ea..f79d314 100644 --- a/tools/change_ip_aio.yml +++ b/tools/change_ip_aio.yml @@ -7,7 +7,7 @@ # 3. 检查下修改是否成功,并且能够成功执行 ansible all -m ping # 4. 运行本脚本 ansible-playbook /etc/ansible/tools/change_ip_aio.yml -- hosts: deploy # hosts 角色无所谓,反正allinone所有角色都是同个ip +- hosts: kube-master # hosts 角色无所谓,反正allinone所有角色都是同个ip tasks: - name: 删除一些证书和配置,后面会以新IP重新生成 file: name={{ item }} state=absent @@ -16,25 +16,25 @@ - "/etc/kubernetes/ssl/kubernetes.pem" # 删除旧master证书 - "/etc/kubernetes/kubelet.kubeconfig" # 删除旧kubelet配置文件 -- hosts: deploy +- hosts: kube-master roles: - deploy - etcd - kube-master - kube-node -- hosts: deploy +- hosts: kube-master 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 }}/" + shell: "{{ bin_dir }}/kubectl delete -f /opt/kube/kube-system/{{ CLUSTER_NETWORK }}.yaml || \ + {{ bin_dir }}/kubectl delete -f /opt/kube/kube-ovn/" ignore_errors: true -- hosts: deploy +- hosts: kube-master roles: - { role: calico, when: "CLUSTER_NETWORK == 'calico'" } - { role: cilium, when: "CLUSTER_NETWORK == 'cilium'" } diff --git a/tools/change_k8s_network.yml b/tools/change_k8s_network.yml index 99b973f..83bd8d0 100644 --- a/tools/change_k8s_network.yml +++ b/tools/change_k8s_network.yml @@ -6,18 +6,16 @@ - name: 获取所有已经创建的POD信息 command: "{{ bin_dir }}/kubectl get daemonset -n kube-system" register: pod_info - delegate_to: "{{ groups.deploy[0] }}" run_once: true - name: 删除原network插件部署 - shell: "{{ bin_dir }}/kubectl delete -f /opt/kube/kube-system/{{ item }}/" + shell: "{{ bin_dir }}/kubectl delete -f /opt/kube/kube-system/{{ item }}.yaml" with_items: - calico - cilium - flannel - kube-router when: 'item in pod_info.stdout' - delegate_to: "{{ groups.deploy[0] }}" run_once: true ignore_errors: true @@ -79,21 +77,6 @@ - kube-proxy ignore_errors: true -- hosts: - - lb - tasks: - - name: 重启lb的keepalived服务 - service: name=keepalived state=restarted - - - 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 - - hosts: - kube-master - kube-node @@ -104,7 +87,7 @@ - { role: flannel, when: "CLUSTER_NETWORK == 'flannel'" } - { role: kube-router, when: "CLUSTER_NETWORK == 'kube-router'" } -- hosts: deploy +- hosts: kube-node tasks: # 删除所有运行pod,由controller自动重建 - name: 重启所有pod @@ -112,4 +95,3 @@ do {{ bin_dir }}/kubectl delete pod --all -n $NS; done;" ignore_errors: true run_once: true - diff --git a/tools/easzctl b/tools/easzctl index 22a0fa0..a6a3fb1 100755 --- a/tools/easzctl +++ b/tools/easzctl @@ -78,7 +78,7 @@ function add-node() { sed -i "/\[kube-node/a $1 NEW_NODE=yes" $BASEPATH/hosts # check if playbook runs successfully - ansible-playbook $BASEPATH/tools/20.addnode.yml -e NODE_TO_ADD=$1 || { sed -i "/$1 NEW_NODE=yes/d" $BASEPATH/hosts; return 2; } + ansible-playbook $BASEPATH/tools/02.addnode.yml -e NODE_TO_ADD=$1 || { sed -i "/$1 NEW_NODE=yes/d" $BASEPATH/hosts; return 2; } # save current cluster context if needed [ -f "$BASEPATH/.cluster/current_cluster" ] && save_context @@ -96,7 +96,7 @@ function add-master() { sed -i "/\[kube-master/a $1 NEW_MASTER=yes" $BASEPATH/hosts # check if playbook runs successfully - ansible-playbook $BASEPATH/tools/21.addmaster.yml -e NODE_TO_ADD=$1 || { sed -i "/$1 NEW_MASTER=yes/d" $BASEPATH/hosts; return 2; } + ansible-playbook $BASEPATH/tools/03.addmaster.yml -e NODE_TO_ADD=$1 || { sed -i "/$1 NEW_MASTER=yes/d" $BASEPATH/hosts; return 2; } # reconfigure and restart the haproxy service on 'kube-node' nodes ansible-playbook $BASEPATH/05.kube-node.yml -t restart_lb || { echo "[ERROR] Failed to restart the haproxy service on 'kube-node' nodes!"; return 2; } @@ -122,7 +122,7 @@ function add-etcd() { sed -i "/\[etcd/a $1 NODE_NAME=$NAME" $BASEPATH/hosts # check if playbook runs successfully - ansible-playbook $BASEPATH/tools/19.addetcd.yml -e NODE_TO_ADD=$1 || { sed -i "/$1 NODE_NAME=$NAME/d" $BASEPATH/hosts; return 2; } + ansible-playbook $BASEPATH/tools/01.addetcd.yml -e NODE_TO_ADD=$1 || { sed -i "/$1 NODE_NAME=$NAME/d" $BASEPATH/hosts; return 2; } # restart apiservers to use the new etcd cluster ansible-playbook $BASEPATH/04.kube-master.yml -t restart_master || { echo "[ERROR] Unexpected failures in master nodes!"; return 2; } @@ -137,7 +137,7 @@ function del-etcd() { [[ $1 =~ ^(2(5[0-5]{1}|[0-4][0-9]{1})|[0-1]?[0-9]{1,2})(\.(2(5[0-5]{1}|[0-4][0-9]{1})|[0-1]?[0-9]{1,2})){3}$ ]] || { echo "[ERROR] Invalid ip address!"; return 2; } # - ansible-playbook $BASEPATH/tools/remove_etcd_node.yml -e ETCD_TO_DEL=$1 + ansible-playbook $BASEPATH/tools/11.deletcd.yml -e ETCD_TO_DEL=$1 || { echo "[ERROR] Failed to delete etcd node: $1!"; return 2; } # restart apiservers to use the new etcd cluster ansible-playbook $BASEPATH/04.kube-master.yml -t restart_master || { echo "[ERROR] Unexpected failures in master nodes!"; return 2; }