From ae8c4cabd03d96c6401b2fd218fc94871f67e490 Mon Sep 17 00:00:00 2001 From: leif160519 Date: Thu, 6 Jun 2024 16:26:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E4=B8=A4=E4=B8=AA=E8=8A=82?= =?UTF-8?q?=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- inventory/hosts | 16 ++++++++++++---- playbooks/add-node.yml | 15 ++++++++++++--- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/inventory/hosts b/inventory/hosts index 8bbe619..733c228 100644 --- a/inventory/hosts +++ b/inventory/hosts @@ -2,15 +2,16 @@ # 如果部署单Master,只保留一个Master节点 # 默认Naster节点也部署Node组件 192.168.31.81 node_name=k8s-master-01 -192.168.31.80 node_name=k8s-master-02 +#192.168.31.80 node_name=k8s-master-02 [node] 192.168.31.82 node_name=k8s-node-01 192.168.31.83 node_name=k8s-node-02 192.168.31.84 node_name=k8s-node-03 +192.168.31.85 node_name=k8s-node-04 [etcd] -192.168.31.80 etcd_name=etcd-2 +#192.168.31.80 etcd_name=etcd-2 192.168.31.81 etcd_name=etcd-1 192.168.31.82 etcd_name=etcd-3 192.168.31.83 etcd_name=etcd-4 @@ -19,11 +20,18 @@ [lb] # 如果部署单Master,该项忽略 192.168.31.81 lb_name=lb-master -192.168.31.80 lb_name=lb-backup +#192.168.31.80 lb_name=lb-backup +[k8s] [k8s:children] master node +newnode + +[off] # 下线机器 +k8s-master-02 [newnode] -192.168.31.85 node_name=k8s-node-04 +#192.168.31.85 node_name=k8s-node-04 +192.168.31.86 node_name=k8s-node-05 +192.168.31.87 node_name=k8s-node-06 diff --git a/playbooks/add-node.yml b/playbooks/add-node.yml index bf332b9..eb6456b 100644 --- a/playbooks/add-node.yml +++ b/playbooks/add-node.yml @@ -1,16 +1,25 @@ --- +- name: -1.给所有节点添加新节点hosts + hosts: k8s + tasks: + - lineinfile: + path: /etc/hosts + line: "{{ hostvars[item].inventory_hostname }} {{ hostvars[item].node_name }}" + with_items: + - "{{ groups['k8s'] }}" + - name: 0.系统初始化 gather_facts: true - hosts: newnode + hosts: newnode roles: - common - tags: common + tags: common - name: 1.部署Docker gather_facts: false hosts: newnode roles: - - docker + - docker tags: docker - name: 2.部署K8S Node