From 6b21f30ab9a9aac34d45bdd2db93de7a22f62b47 Mon Sep 17 00:00:00 2001 From: gjmzj Date: Sat, 15 Sep 2018 11:27:33 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=AE=89=E8=A3=85=E6=AD=A5?= =?UTF-8?q?=E9=AA=A4=E4=B8=ADkubectl=E7=9A=84=E6=89=A7=E8=A1=8C=E4=BB=A5?= =?UTF-8?q?=E9=80=82=E5=90=88=E5=85=AC=E6=9C=89=E4=BA=91=E9=83=A8=E7=BD=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 04.kube-master.yml | 2 ++ 21.addmaster.yml | 2 ++ roles/kube-master/tasks/main.yml | 1 + roles/kube-node/tasks/main.yml | 4 ++++ 4 files changed, 9 insertions(+) diff --git a/04.kube-master.yml b/04.kube-master.yml index e62cdb4..def90cb 100644 --- a/04.kube-master.yml +++ b/04.kube-master.yml @@ -6,9 +6,11 @@ tasks: - name: 禁止业务 pod调度到 master节点 shell: "{{ bin_dir }}/kubectl cordon {{ inventory_hostname }} " + delegate_to: "{{ groups.deploy[0] }}" when: DEPLOY_MODE != "allinone" ignore_errors: true - name: 设置master节点role shell: "{{ bin_dir }}/kubectl label node {{ inventory_hostname }} kubernetes.io/role=master --overwrite" ignore_errors: true + delegate_to: "{{ groups.deploy[0] }}" diff --git a/21.addmaster.yml b/21.addmaster.yml index 7983bd4..24804ea 100644 --- a/21.addmaster.yml +++ b/21.addmaster.yml @@ -22,9 +22,11 @@ tasks: - name: 禁止业务 pod调度到 master节点 shell: "{{ bin_dir }}/kubectl cordon {{ inventory_hostname }} " + delegate_to: "{{ groups.deploy[0] }}" when: DEPLOY_MODE != "allinone" ignore_errors: true - name: 设置master节点role shell: "{{ bin_dir }}/kubectl label node {{ inventory_hostname }} kubernetes.io/role=master --overwrite" ignore_errors: true + delegate_to: "{{ groups.deploy[0] }}" diff --git a/roles/kube-master/tasks/main.yml b/roles/kube-master/tasks/main.yml index 504d53f..af656f2 100644 --- a/roles/kube-master/tasks/main.yml +++ b/roles/kube-master/tasks/main.yml @@ -65,5 +65,6 @@ until: result.rc == 0 retries: 5 delay: 6 + delegate_to: "{{ groups.deploy[0] }}" run_once: True tags: upgrade_k8s, restart_master diff --git a/roles/kube-node/tasks/main.yml b/roles/kube-node/tasks/main.yml index 88eebfa..7c12969 100644 --- a/roles/kube-node/tasks/main.yml +++ b/roles/kube-node/tasks/main.yml @@ -97,6 +97,7 @@ - name: 获取csr 请求信息 shell: "sleep 3 && {{ bin_dir }}/kubectl get csr" + delegate_to: "{{ groups.deploy[0] }}" register: csr_info run_once: true @@ -104,11 +105,13 @@ shell: "{{ bin_dir }}/kubectl get csr|grep 'Pending' | awk 'NR>0{print $1}'| \ xargs {{ bin_dir }}/kubectl certificate approve" when: '"Pending" in csr_info.stdout' + delegate_to: "{{ groups.deploy[0] }}" run_once: true - name: 轮询等待node达到Ready状态 shell: "{{ bin_dir }}/kubectl get node {{ inventory_hostname }}|awk 'NR>1{print $2}'" register: node_status + delegate_to: "{{ groups.deploy[0] }}" until: node_status.stdout == "Ready" or node_status.stdout == "Ready,SchedulingDisabled" retries: 8 delay: 8 @@ -117,3 +120,4 @@ - name: 设置node节点role shell: "{{ bin_dir }}/kubectl label node {{ inventory_hostname }} kubernetes.io/role=node --overwrite" ignore_errors: true + delegate_to: "{{ groups.deploy[0] }}"