From 3014dfef24effa7f137aab1238dd4b0ef0b50f22 Mon Sep 17 00:00:00 2001 From: Smaine Kahlouch Date: Sun, 6 Dec 2015 20:39:03 +0100 Subject: [PATCH] Clustering etcd for ha masters --- roles/etcd/templates/etcd2.j2 | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/roles/etcd/templates/etcd2.j2 b/roles/etcd/templates/etcd2.j2 index 27143e458..cb3305287 100644 --- a/roles/etcd/templates/etcd2.j2 +++ b/roles/etcd/templates/etcd2.j2 @@ -1,17 +1,16 @@ # etcd2.0 +{% set etcd = {} %} +{% for srv in groups['kube-master'] %} +{% if inventory_hostname == srv %} +{% set _dummy = etcd.update({'name':"master"+loop.index|string}) %} +{% endif %} +{% endfor %} [Service] -{% if inventory_hostname in groups['kube-master'] %} -Environment="ETCD_ADVERTISE_CLIENT_URLS=http://{{ ansible_default_ipv4.address }}:2379,http://{{ ansible_default_ipv4.address }}:4001" -Environment="ETCD_INITIAL_ADVERTISE_PEER_URLS=http://{{ ansible_default_ipv4.address }}:2380" -Environment="ETCD_INITIAL_CLUSTER=master=http://{{ ansible_default_ipv4.address }}:2380" +Environment="ETCD_ADVERTISE_CLIENT_URLS=http://{{ hostvars[inventory_hostname]['ip'] | default( ansible_default_ipv4.address) }}:2379" +Environment="ETCD_INITIAL_ADVERTISE_PEER_URLS=http://{{ hostvars[inventory_hostname]['ip'] | default( ansible_default_ipv4.address) }}:2380" +Environment="ETCD_INITIAL_CLUSTER={% for srv in groups['kube-master'] %}master{{ loop.index|string }}=http://{{ srv }}:2380{% if not loop.last %},{% endif %}{% endfor %}" Environment="ETCD_INITIAL_CLUSTER_STATE=new" Environment="ETCD_INITIAL_CLUSTER_TOKEN=k8s_etcd" -Environment="ETCD_LISTEN_CLIENT_URLS=http://0.0.0.0:2379,http://0.0.0.0:4001" -Environment="ETCD_LISTEN_PEER_URLS=http://:2380,http://{{ ansible_default_ipv4.address }}:7001" -Environment="ETCD_NAME=master" -{% else %} -Environment="ETCD_ADVERTISE_CLIENT_URLS=http://0.0.0.0:2379,http://0.0.0.0:4001" -Environment="ETCD_INITIAL_CLUSTER=master=http://{{ groups['kube-master'][0] }}:2380" -Environment="ETCD_LISTEN_CLIENT_URLS=http://0.0.0.0:2379,http://0.0.0.0:4001" -Environment="ETCD_PROXY=on" -{% endif %} +Environment="ETCD_LISTEN_CLIENT_URLS=http://{{ hostvars[inventory_hostname]['ip'] | default( ansible_default_ipv4.address) }}:2379,http://127.0.0.1:2379" +Environment="ETCD_LISTEN_PEER_URLS=http://{{ hostvars[inventory_hostname]['ip'] | default( ansible_default_ipv4.address) }}:2380" +Environment="ETCD_NAME={{ etcd.name }}"