From 81bb83b3b7dfbf974340198ab2dd6269f6b5bad0 Mon Sep 17 00:00:00 2001 From: gjmzj Date: Fri, 15 Feb 2019 10:10:43 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=A2=9E=E5=8A=A0node/?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0master=E8=8A=82=E7=82=B9=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 19.addetcd.yml | 2 +- 20.addnode.yml | 28 ++++++++++++++++++++++++++++ 21.addmaster.yml | 28 ++++++++++++++++++++++++++++ docs/op/AddMaster.md | 3 +++ docs/op/AddNode.md | 3 +++ 5 files changed, 63 insertions(+), 1 deletion(-) diff --git a/19.addetcd.yml b/19.addetcd.yml index cde6813..2b4c598 100644 --- a/19.addetcd.yml +++ b/19.addetcd.yml @@ -38,7 +38,7 @@ lineinfile: dest: "{{ base_dir }}/hosts" state: present - insertafter: '^\[etcd\]' + insertafter: '^\[etcd' firstmatch: yes line: "{{ inventory_hostname }} NODE_NAME={{ NODE_NAME }}" connection: local diff --git a/20.addnode.yml b/20.addnode.yml index 99d5f8d..75a875f 100644 --- a/20.addnode.yml +++ b/20.addnode.yml @@ -9,3 +9,31 @@ - { role: cilium, when: "CLUSTER_NETWORK == 'cilium'" } - { role: flannel, when: "CLUSTER_NETWORK == 'flannel'" } - { role: kube-router, when: "CLUSTER_NETWORK == 'kube-router'" } + +# modify the ansible hosts file +- hosts: + - new-node + tasks: + - name: tag new-node FINISHED=yes + shell: 'sed -i "/\[new-node/,/\[harbor/s/{{ inventory_hostname }}/{{ inventory_hostname }} FINISHED=yes/" {{ base_dir }}/hosts' + args: + warn: false + connection: local + + - name: cp new-node to 'kube-node' group + lineinfile: + dest: "{{ base_dir }}/hosts" + state: present + insertafter: '^\[kube-node' + firstmatch: yes + line: "{{ inventory_hostname }} NEW_NODE=yes" + connection: local + +- hosts: deploy + tasks: + - name: rm new-node in ansible hosts + lineinfile: + dest: "{{ base_dir }}/hosts" + state: absent + regexp: 'FINISHED=yes' + connection: local diff --git a/21.addmaster.yml b/21.addmaster.yml index 097efcd..dd13466 100644 --- a/21.addmaster.yml +++ b/21.addmaster.yml @@ -27,3 +27,31 @@ shell: "{{ bin_dir }}/kubectl label node {{ inventory_hostname }} kubernetes.io/role=master --overwrite" ignore_errors: true delegate_to: "{{ groups.deploy[0] }}" + +# modify the ansible hosts file +- hosts: + - new-master + tasks: + - name: tag new-master FINISHED=yes + shell: 'sed -i "/\[new-master/,/\[kube-node/s/{{ inventory_hostname }}/{{ inventory_hostname }} FINISHED=yes/" {{ base_dir }}/hosts' + args: + warn: false + connection: local + + - name: cp new-master to 'kube-master' group + lineinfile: + dest: "{{ base_dir }}/hosts" + state: present + insertafter: '^\[kube-master' + firstmatch: yes + line: "{{ inventory_hostname }} NEW_MASTER=yes" + connection: local + +- hosts: deploy + tasks: + - name: rm new-master in ansible hosts + lineinfile: + dest: "{{ base_dir }}/hosts" + state: absent + regexp: 'FINISHED=yes' + connection: local diff --git a/docs/op/AddMaster.md b/docs/op/AddMaster.md index b3344f1..d173028 100644 --- a/docs/op/AddMaster.md +++ b/docs/op/AddMaster.md @@ -10,6 +10,7 @@ - 新节点安装 kube-node 服务 - 新节点安装网络插件相关 - 禁止业务 pod调度到新master节点 +- 修改hosts文件,把 new-master 组成员转移到 kube-master 组 ### 操作步骤 @@ -54,3 +55,5 @@ NAME STATUS ROLES AGE VERSION ### 后续 上述步骤验证成功,确认新节点工作正常后,为了方便后续再次添加节点,在ansible hosts文件中,把 [new-master] 组下的节点全部复制到 [kube-master] 组下,并清空 [new-master] 组中的节点。 + +- 注:新版本 kubeasz 已经自动完成 new-master 组成员转移到 kube-master 组 diff --git a/docs/op/AddNode.md b/docs/op/AddNode.md index 63a2693..b0f8585 100644 --- a/docs/op/AddNode.md +++ b/docs/op/AddNode.md @@ -5,6 +5,7 @@ - 新节点安装 docker 服务 - 新节点安装 kube-node 服务 - 新节点安装网络插件相关 +- 修改hosts文件,把 new-node 组成员转移到 kube-node 组 ### 操作步骤 @@ -40,3 +41,5 @@ $ kubectl get pod -n kube-system ### 后续 上述步骤验证成功,确认新节点工作正常后,为了方便后续再次添加节点,在ansible hosts文件中,把 [new-node] 组下的节点全部复制到 [kube-node] 组下,并清空 [new-node] 组的节点。 + +- 注:新版本 kubeasz 已经自动完成 new-node 组成员转移到 kube-node 组