ha etcd with calico

This commit is contained in:
Smaine Kahlouch 2015-12-15 11:49:11 +01:00
parent 2fc8b46996
commit e2984b4fdb
8 changed files with 38 additions and 33 deletions

View file

@ -4,13 +4,9 @@
roles: roles:
- { role: download, tags: download } - { role: download, tags: download }
# etcd must be running on master(s) before going on
- hosts: etcd
roles:
- { role: etcd, tags: etcd }
- hosts: k8s-cluster - hosts: k8s-cluster
roles: roles:
- { role: etcd, tags: etcd }
- { role: docker, tags: docker } - { role: docker, tags: docker }
- { role: dnsmasq, tags: dnsmasq } - { role: dnsmasq, tags: dnsmasq }
- { role: network_plugin, tags: ['calico', 'flannel', 'network'] } - { role: network_plugin, tags: ['calico', 'flannel', 'network'] }

View file

@ -1,15 +1,14 @@
--- ---
- name: restart daemons
command: /bin/true
notify:
- reload systemd
- restart etcd2
- name: reload systemd - name: reload systemd
command: systemctl daemon-reload command: systemctl daemon-reload
- name: restart etcd2 - name: restart reloaded-etcd2
service: name=etcd2 state=restarted service:
name: etcd2
state: restarted
- name: Save iptables rules - name: restart etcd2
command: service iptables save command: /bin/true
notify:
- reload systemd
- restart reloaded-etcd2

View file

@ -1,11 +1,18 @@
--- ---
- name: Copy etcd2.service systemd file
template:
src: systemd-etcd2.service.j2
dest: /lib/systemd/system/etcd2.service
backup: yes
notify:
- restart etcd2
- name: Create etcd2 environment vars dir - name: Create etcd2 environment vars dir
file: path=/etc/systemd/system/etcd2.service.d state=directory file: path=/etc/systemd/system/etcd2.service.d state=directory
- name: Write etcd2 config file - name: Write etcd2 config file
template: src=etcd2.j2 dest=/etc/systemd/system/etcd2.service.d/10-etcd2-cluster.conf backup=yes template: src=etcd2.j2 dest=/etc/systemd/system/etcd2.service.d/10-etcd2.conf backup=yes
notify: notify:
- reload systemd
- restart etcd2 - restart etcd2
- name: Ensure etcd2 is running - name: Ensure etcd2 is running

View file

@ -11,15 +11,7 @@
with_items: with_items:
- etcdctl - etcdctl
- etcd - etcd
notify: notify: restart etcd2
- restart daemons
- name: Create etcd2 binary symlink - name: Create etcd2 binary symlink
file: src=/usr/local/bin/etcd dest=/usr/local/bin/etcd2 state=link file: src=/usr/local/bin/etcd dest=/usr/local/bin/etcd2 state=link
- name: Copy etcd2.service systemd file
template:
src: systemd-etcd2.service.j2
dest: /lib/systemd/system/etcd2.service
backup: yes
notify: restart daemons

View file

@ -1,16 +1,21 @@
# etcd2.0 # etcd2.0
[Service]
{% if inventory_hostname in groups['etcd'] %}
{% set etcd = {} %} {% set etcd = {} %}
{% for srv in groups['kube-master'] %} {% for srv in groups['etcd'] %}
{% if inventory_hostname == srv %} {% if inventory_hostname == srv %}
{% set _dummy = etcd.update({'name':"master"+loop.index|string}) %} {% set _dummy = etcd.update({'name':"master"+loop.index|string}) %}
{% endif %} {% endif %}
{% endfor %} {% endfor %}
[Service]
Environment="ETCD_ADVERTISE_CLIENT_URLS=http://{{ hostvars[inventory_hostname]['ip'] | default( ansible_default_ipv4.address) }}:2379" 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_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={% for srv in groups['etcd'] %}master{{ loop.index|string }}=http://{{ srv }}:2380{% if not loop.last %},{% endif %}{% endfor %}"
Environment="ETCD_INITIAL_CLUSTER_STATE=new" Environment="ETCD_INITIAL_CLUSTER_STATE=new"
Environment="ETCD_INITIAL_CLUSTER_TOKEN=k8s_etcd" Environment="ETCD_INITIAL_CLUSTER_TOKEN=k8s_etcd"
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_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_LISTEN_PEER_URLS=http://{{ hostvars[inventory_hostname]['ip'] | default( ansible_default_ipv4.address) }}:2380"
Environment="ETCD_NAME={{ etcd.name }}" Environment="ETCD_NAME={{ etcd.name }}"
{% else %}
Environment="ETCD_INITIAL_CLUSTER={% for srv in groups['etcd'] %}master{{ loop.index|string }}=http://{{ srv }}:2380{% if not loop.last %},{% endif %}{% endfor %}"
Environment="ETCD_LISTEN_CLIENT_URLS=http://127.0.0.1:23799"
{% endif %}

View file

@ -6,7 +6,11 @@ Conflicts=etcd.service
User=etcd User=etcd
Environment=ETCD_DATA_DIR=/var/lib/etcd2 Environment=ETCD_DATA_DIR=/var/lib/etcd2
Environment=ETCD_NAME=%m Environment=ETCD_NAME=%m
{% if inventory_hostname in groups['etcd'] %}
ExecStart={{ bin_dir }}/etcd2 ExecStart={{ bin_dir }}/etcd2
{% else %}
ExecStart={{ bin_dir }}/etcd2 -proxy on
{% endif %}
Restart=always Restart=always
RestartSec=10s RestartSec=10s
LimitNOFILE=40000 LimitNOFILE=40000

View file

@ -12,7 +12,7 @@
- name: Calico | Configure calico-node desired pool - name: Calico | Configure calico-node desired pool
shell: calicoctl pool add {{ kube_pods_subnet }} shell: calicoctl pool add {{ kube_pods_subnet }}
environment: environment:
ETCD_AUTHORITY: "{{ loadbalancer_address | default(groups['kube-master'][0]) }}:2379" ETCD_AUTHORITY: "{{ groups['etcd'][0] }}:2379"
run_once: true run_once: true
- name: Calico | Write calico-node systemd init file - name: Calico | Write calico-node systemd init file

View file

@ -4,20 +4,22 @@
CALICO_IPAM=true CALICO_IPAM=true
DEFAULT_IPV4={{ip | default(ansible_default_ipv4.address) }} DEFAULT_IPV4={{ip | default(ansible_default_ipv4.address) }}
{% if inventory_hostname in groups['kube-node'] %}
# The kubernetes master IP # The kubernetes master IP
KUBERNETES_MASTER={{ groups['kube-master'][0] }} KUBERNETES_MASTER={{ groups['kube-master'][0] }}
# Location of etcd cluster used by Calico. By default, this uses the etcd # Location of etcd cluster used by Calico. By default, this uses the etcd
# instance running on the Kubernetes Master # instance running on the Kubernetes Master
ETCD_AUTHORITY={{ loadbalancer_address | default(groups['kube-master'][0]) }}:2379 {% if inventory_hostname in groups['etcd'] %}
ETCD_AUTHORITY="127.0.0.1:2379"
{% else %}
ETCD_AUTHORITY="127.0.0.1:23799"
{% endif %}
# The kubernetes-apiserver location - used by the calico plugin # The kubernetes-apiserver location - used by the calico plugin
KUBE_API_ROOT=http://{{ groups['kube-master'][0] }}:{{kube_apiserver_insecure_port}}/api/v1/ KUBE_API_ROOT=http://{{ groups['kube-master'][0] }}:{{kube_apiserver_insecure_port}}/api/v1/
# Location of the calicoctl binary - used by the calico plugin # Location of the calicoctl binary - used by the calico plugin
CALICOCTL_PATH="{{ bin_dir }}/calicoctl" CALICOCTL_PATH="{{ bin_dir }}/calicoctl"
{% endif %}
{% else %} {% else %}
FLANNEL_ETCD_PREFIX="--etcd-prefix=/{{ cluster_name }}/network" FLANNEL_ETCD_PREFIX="--etcd-prefix=/{{ cluster_name }}/network"
{% endif %} {% endif %}