Remove templating for etcd members

Use a etcd-initer init container to generate etcd args, it determines
etcd name by comparing its ip and etcd cluster ips. This way will
make etcd configuration independent to the ansible templating so
that could be easier on adding master nodes.
pull/2037/head
Wei Tie 2017-12-07 23:33:29 -08:00
parent 5881ba43f8
commit dad95c873b
4 changed files with 26 additions and 28 deletions

View File

@ -1,29 +1,19 @@
--- ---
contiv_config_dir: "{{ kube_config_dir }}/contiv" contiv_config_dir: "{{ kube_config_dir }}/contiv"
contiv_etcd_conf_dir: "/etc/contiv/etcd/" contiv_etcd_conf_dir: "/etc/contiv/etcd"
contiv_etcd_data_dir: "/var/lib/etcd/contiv-data" contiv_etcd_data_dir: "/var/lib/etcd/contiv-data"
contiv_netmaster_port: 9999 contiv_netmaster_port: 9999
contiv_cni_version: 0.1.0 contiv_cni_version: 0.1.0
contiv_etcd_image_repo: "{{ etcd_image_repo }}" contiv_etcd_image_repo: "{{ etcd_image_repo }}"
contiv_etcd_image_tag: "{{ etcd_image_tag }}" contiv_etcd_image_tag: "{{ etcd_image_tag }}"
contiv_etcd_listen_ip: "{{ ip | default(ansible_default_ipv4['address']) }}"
contiv_etcd_listen_port: 6666 contiv_etcd_listen_port: 6666
contiv_etcd_peer_port: 6667 contiv_etcd_peer_port: 6667
contiv_etcd_ad_urls: http://{{ contiv_etcd_listen_ip }}:{{ contiv_etcd_listen_port }}
contiv_etcd_peer_urls: http://{{ contiv_etcd_listen_ip }}:{{ contiv_etcd_peer_port }}
contiv_etcd_listen_urls:
- http://{{ contiv_etcd_listen_ip }}:{{ contiv_etcd_listen_port }}
- http://127.0.0.1:{{ contiv_etcd_listen_port }}
contiv_etcd_endpoints: |- contiv_etcd_endpoints: |-
{% for host in groups['kube-master'] -%} {% for host in groups['kube-master'] -%}
contiv_etcd{{ loop.index }}=http://{{ hostvars[host]['ip'] | default(hostvars[host].ansible_default_ipv4['address']) }}:{{ contiv_etcd_peer_port }}{% if not loop.last %},{% endif %} contiv_etcd{{ loop.index }}=http://{{ hostvars[host]['ip'] | default(hostvars[host].ansible_default_ipv4['address']) }}:{{ contiv_etcd_peer_port }}{% if not loop.last %},{% endif %}
{%- endfor %} {%- endfor %}
contiv_etcd_name: |-
{% for host in groups['kube-master'] %}
{% if host == inventory_hostname -%}contiv_etcd{{ loop.index }}{%- endif %}
{% endfor %}
# Parameters for Contiv api-proxy # Parameters for Contiv api-proxy
contiv_enable_api_proxy: true contiv_enable_api_proxy: true

View File

@ -17,12 +17,6 @@
- "{{ contiv_etcd_conf_dir }}" - "{{ contiv_etcd_conf_dir }}"
- "{{ contiv_etcd_data_dir }}" - "{{ contiv_etcd_data_dir }}"
- name: Contiv | Create contiv etcd config env
template:
src: contiv-etcd.env.j2
dest: "{{ contiv_etcd_conf_dir }}/contiv-etcd.env"
when: inventory_hostname in groups['kube-master']
- set_fact: - set_fact:
contiv_config_dir: "{{ contiv_config_dir }}" contiv_config_dir: "{{ contiv_config_dir }}"
contiv_enable_api_proxy: "{{ contiv_enable_api_proxy }}" contiv_enable_api_proxy: "{{ contiv_enable_api_proxy }}"

View File

@ -1,8 +0,0 @@
# contiv etcd config
export ETCD_DATA_DIR=/var/lib/etcd/contiv-data
export ETCD_ADVERTISE_CLIENT_URLS={{ contiv_etcd_ad_urls }}
export ETCD_INITIAL_ADVERTISE_PEER_URLS={{ contiv_etcd_peer_urls }}
export ETCD_LISTEN_PEER_URLS={{ contiv_etcd_peer_urls }}
export ETCD_LISTEN_CLIENT_URLS={{ contiv_etcd_listen_urls | join(",") }}
export ETCD_NAME={{ contiv_etcd_name }}
export ETCD_INITIAL_CLUSTER={{ contiv_etcd_endpoints }}

View File

@ -24,12 +24,34 @@ spec:
tolerations: tolerations:
- key: node-role.kubernetes.io/master - key: node-role.kubernetes.io/master
effect: NoSchedule effect: NoSchedule
initContainers:
- name: contiv-etcd-init
image: ferest/etcd-initer:latest
imagePullPolicy: Always
env:
- name: ETCD_INIT_ARGSFILE
value: '{{ contiv_etcd_conf_dir }}/contiv-etcd-args'
- name: ETCD_INIT_LISTEN_PORT
value: '{{ contiv_etcd_listen_port }}'
- name: ETCD_INIT_PEER_PORT
value: '{{ contiv_etcd_peer_port }}'
- name: ETCD_INIT_CLUSTER
value: '{{ contiv_etcd_endpoints }}'
- name: ETCD_INIT_DATA_DIR
value: '{{ contiv_etcd_data_dir }}'
volumeMounts:
- name: contiv-etcd-conf-dir
mountPath: {{ contiv_etcd_conf_dir }}
containers: containers:
- name: contiv-etcd - name: contiv-etcd
image: {{ contiv_etcd_image_repo }}:{{ contiv_etcd_image_tag }} image: {{ contiv_etcd_image_repo }}:{{ contiv_etcd_image_tag }}
command: ["sh","-c"] command:
args: - sh
- '. {{ contiv_etcd_conf_dir }}/contiv-etcd.env && /usr/local/bin/etcd' - -c
- "/usr/local/bin/etcd $(cat $ETCD_INIT_ARGSFILE)"
env:
- name: ETCD_INIT_ARGSFILE
value: {{ contiv_etcd_conf_dir }}/contiv-etcd-args
volumeMounts: volumeMounts:
- name: contiv-etcd-conf-dir - name: contiv-etcd-conf-dir
mountPath: {{ contiv_etcd_conf_dir }} mountPath: {{ contiv_etcd_conf_dir }}