From effd27a5f609874f7b0d3eff2434bf843eacf070 Mon Sep 17 00:00:00 2001 From: elementyang Date: Tue, 3 Jul 2018 22:02:44 +0800 Subject: [PATCH 1/2] change the way that getting etcd_member_name --- README.md | 2 +- inventory/sample/hosts.ini | 13 +++++++------ roles/kubespray-defaults/defaults/main.yaml | 7 ++++--- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index e566ccd0e..bdaf7f78f 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ To deploy the cluster you can use : sudo pip install -r requirements.txt # Copy ``inventory/sample`` as ``inventory/mycluster`` - cp -rfp inventory/sample inventory/mycluster + cp -rfp inventory/sample/* inventory/mycluster # Update Ansible inventory file with inventory builder declare -a IPS=(10.10.1.3 10.10.1.4 10.10.1.5) diff --git a/inventory/sample/hosts.ini b/inventory/sample/hosts.ini index bddfa2f80..c01c73ad4 100644 --- a/inventory/sample/hosts.ini +++ b/inventory/sample/hosts.ini @@ -1,11 +1,12 @@ # ## Configure 'ip' variable to bind kubernetes services on a # ## different ip than the default iface -# node1 ansible_host=95.54.0.12 # ip=10.3.0.1 -# node2 ansible_host=95.54.0.13 # ip=10.3.0.2 -# node3 ansible_host=95.54.0.14 # ip=10.3.0.3 -# node4 ansible_host=95.54.0.15 # ip=10.3.0.4 -# node5 ansible_host=95.54.0.16 # ip=10.3.0.5 -# node6 ansible_host=95.54.0.17 # ip=10.3.0.6 +# ## We should set etcd_member_name for etcd cluster. The node that is not a etcd member do not need to set the value, or can set the empty string value. +# node1 ansible_host=95.54.0.12 # ip=10.3.0.1 etcd_member_name=etcd1 +# node2 ansible_host=95.54.0.13 # ip=10.3.0.2 etcd_member_name=etcd2 +# node3 ansible_host=95.54.0.14 # ip=10.3.0.3 etcd_member_name=etcd3 +# node4 ansible_host=95.54.0.15 # ip=10.3.0.4 etcd_member_name=etcd4 +# node5 ansible_host=95.54.0.16 # ip=10.3.0.5 etcd_member_name=etcd5 +# node6 ansible_host=95.54.0.17 # ip=10.3.0.6 etcd_member_name=etcd6 # ## configure a bastion host if your nodes are not directly reachable # bastion ansible_host=x.x.x.x ansible_user=some_user diff --git a/roles/kubespray-defaults/defaults/main.yaml b/roles/kubespray-defaults/defaults/main.yaml index 347150850..489c1e5f2 100644 --- a/roles/kubespray-defaults/defaults/main.yaml +++ b/roles/kubespray-defaults/defaults/main.yaml @@ -335,15 +335,16 @@ etcd_events_access_addresses: |- {% for item in groups['etcd'] -%} https://{{ hostvars[item]['access_ip'] | default(hostvars[item]['ip'] | default(hostvars[item]['ansible_default_ipv4']['address'])) }}:2381{% if not loop.last %},{% endif %} {%- endfor %} +# user should set etcd_member_name in inventory/mycluster/hosts.ini etcd_member_name: |- {% for host in groups['etcd'] %} - {% if inventory_hostname == host %}{{"etcd"+loop.index|string }}{% endif %} + {% if inventory_hostname == host %}{{ hostvars[host].etcd_member_name }}{% endif %} {% endfor %} etcd_peer_addresses: |- {% for item in groups['etcd'] -%} - {{ "etcd"+loop.index|string }}=https://{{ hostvars[item].access_ip | default(hostvars[item].ip | default(hostvars[item].ansible_default_ipv4['address'])) }}:2380{% if not loop.last %},{% endif %} + {{ hostvars[item].etcd_member_name }}=https://{{ hostvars[item].access_ip | default(hostvars[item].ip | default(hostvars[item].ansible_default_ipv4['address'])) }}:2380{% if not loop.last %},{% endif %} {%- endfor %} etcd_events_peer_addresses: |- {% for item in groups['etcd'] -%} - {{ "etcd"+loop.index|string }}-events=https://{{ hostvars[item].access_ip | default(hostvars[item].ip | default(hostvars[item].ansible_default_ipv4['address'])) }}:2382{% if not loop.last %},{% endif %} + {{ hostvars[item].etcd_member_name }}-events=https://{{ hostvars[item].access_ip | default(hostvars[item].ip | default(hostvars[item].ansible_default_ipv4['address'])) }}:2382{% if not loop.last %},{% endif %} {%- endfor %} From 5a4f07adca3db50867e6921c8b319185e2814d7d Mon Sep 17 00:00:00 2001 From: elementyang Date: Thu, 5 Jul 2018 00:06:37 +0800 Subject: [PATCH 2/2] change the way of getting etcd_member_name --- roles/kubespray-defaults/defaults/main.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/roles/kubespray-defaults/defaults/main.yaml b/roles/kubespray-defaults/defaults/main.yaml index 489c1e5f2..aee8dacd1 100644 --- a/roles/kubespray-defaults/defaults/main.yaml +++ b/roles/kubespray-defaults/defaults/main.yaml @@ -338,13 +338,13 @@ etcd_events_access_addresses: |- # user should set etcd_member_name in inventory/mycluster/hosts.ini etcd_member_name: |- {% for host in groups['etcd'] %} - {% if inventory_hostname == host %}{{ hostvars[host].etcd_member_name }}{% endif %} + {% if inventory_hostname == host %}{{ hostvars[host].etcd_member_name | default("etcd" + loop.index|string) }}{% endif %} {% endfor %} etcd_peer_addresses: |- {% for item in groups['etcd'] -%} - {{ hostvars[item].etcd_member_name }}=https://{{ hostvars[item].access_ip | default(hostvars[item].ip | default(hostvars[item].ansible_default_ipv4['address'])) }}:2380{% if not loop.last %},{% endif %} + {{ hostvars[item].etcd_member_name | default("etcd" + loop.index|string) }}=https://{{ hostvars[item].access_ip | default(hostvars[item].ip | default(hostvars[item].ansible_default_ipv4['address'])) }}:2380{% if not loop.last %},{% endif %} {%- endfor %} etcd_events_peer_addresses: |- {% for item in groups['etcd'] -%} - {{ hostvars[item].etcd_member_name }}-events=https://{{ hostvars[item].access_ip | default(hostvars[item].ip | default(hostvars[item].ansible_default_ipv4['address'])) }}:2382{% if not loop.last %},{% endif %} + {{ hostvars[item].etcd_member_name | default("etcd" + loop.index|string) }}-events=https://{{ hostvars[item].access_ip | default(hostvars[item].ip | default(hostvars[item].ansible_default_ipv4['address'])) }}:2382{% if not loop.last %},{% endif %} {%- endfor %}