mirror of https://github.com/easzlab/kubeasz.git
fix: set /etc/hosts entries for k8s_nodename
parent
b3b6bb4347
commit
f7f581be40
|
@ -1,4 +1,15 @@
|
|||
# Note: this playbook can not run independently
|
||||
- hosts: "{{ NODE_TO_ADD }}"
|
||||
tasks:
|
||||
- name: 设置 k8s_nodename 在 master、node 节点 /etc/hosts 地址解析
|
||||
lineinfile:
|
||||
dest: /etc/hosts
|
||||
state: present
|
||||
regexp: "{{ K8S_NODENAME }} .* generated by kubeasz"
|
||||
line: "{{ inventory_hostname }} {{ K8S_NODENAME }} # generated by kubeasz"
|
||||
delegate_to: "{{ item }}"
|
||||
with_items: ["{{ groups.kube_master }}", "{{ groups.kube_node }}"]
|
||||
when: "inventory_hostname != K8S_NODENAME"
|
||||
|
||||
- hosts: "{{ NODE_TO_ADD }}"
|
||||
roles:
|
||||
|
|
|
@ -1,4 +1,15 @@
|
|||
# Note: this playbook cann't run independently
|
||||
- hosts: "{{ NODE_TO_ADD }}"
|
||||
tasks:
|
||||
- name: 设置 k8s_nodename 在 master、node 节点 /etc/hosts 地址解析
|
||||
lineinfile:
|
||||
dest: /etc/hosts
|
||||
state: present
|
||||
regexp: "{{ K8S_NODENAME }} .* generated by kubeasz"
|
||||
line: "{{ inventory_hostname }} {{ K8S_NODENAME }} # generated by kubeasz"
|
||||
delegate_to: "{{ item }}"
|
||||
with_items: ["{{ groups.kube_master }}", "{{ groups.kube_node }}"]
|
||||
when: "inventory_hostname != K8S_NODENAME"
|
||||
|
||||
- hosts: "{{ NODE_TO_ADD }}"
|
||||
roles:
|
||||
|
|
|
@ -42,12 +42,30 @@
|
|||
regexp: 'easzlab.io.local'
|
||||
line: "{{ ansible_env.SSH_CLIENT.split(' ')[0] }} easzlab.io.local"
|
||||
|
||||
- name: 设置 k8s_nodename 在 master、node 节点 /etc/hosts 地址解析
|
||||
# 设置节点名称{{ K8S_NODENAME }} /etc/hosts 解析
|
||||
# 1.先确保第一个主节点做好解析
|
||||
# 2.然后复制给集群所有节点
|
||||
- name: 设置 k8s_nodename 在 master[0] 节点 /etc/hosts 地址解析
|
||||
lineinfile:
|
||||
dest: /etc/hosts
|
||||
state: present
|
||||
regexp: "{{ K8S_NODENAME }}"
|
||||
line: "{{ inventory_hostname }} {{ K8S_NODENAME }}"
|
||||
delegate_to: "{{ item }}"
|
||||
with_items: ["{{ groups.kube_master }}", "{{ groups.kube_node }}"]
|
||||
regexp: "{{ K8S_NODENAME }} .* generated by kubeasz"
|
||||
line: "{{ inventory_hostname }} {{ K8S_NODENAME }} # generated by kubeasz"
|
||||
delegate_to: "{{ groups.kube_master[0] }}"
|
||||
when: "inventory_hostname != K8S_NODENAME"
|
||||
|
||||
- name: 获取 master[0] 节点由kubeasz 创建的 /etc/hosts 地址解析
|
||||
shell: 'grep "generated by kubeasz" /etc/hosts'
|
||||
register: RESOLVE_K8S_NODENAME
|
||||
delegate_to: "{{ groups.kube_master[0] }}"
|
||||
run_once: true
|
||||
|
||||
#- debug: var="RESOLVE_K8S_NODENAME.stdout"
|
||||
# run_once: true
|
||||
|
||||
- name: 设置 /etc/hosts 地址解析
|
||||
blockinfile:
|
||||
path: /etc/hosts
|
||||
block: |
|
||||
{{ RESOLVE_K8S_NODENAME.stdout }}
|
||||
when: "inventory_hostname != groups.kube_master[0]"
|
||||
|
|
Loading…
Reference in New Issue