2015-10-04 04:19:50 +08:00
|
|
|
---
|
2016-12-07 19:13:12 +08:00
|
|
|
- name: Calico | Check calicoctl version
|
|
|
|
run_once: true
|
|
|
|
set_fact:
|
|
|
|
legacy_calicoctl: "{{ calicoctl_image_tag | version_compare('v1.0.0', '<') }}"
|
2016-12-08 21:36:00 +08:00
|
|
|
tags: facts
|
2016-12-07 19:13:12 +08:00
|
|
|
|
2016-11-14 15:48:28 +08:00
|
|
|
- name: Calico | Write Calico cni config
|
|
|
|
template:
|
|
|
|
src: "cni-calico.conf.j2"
|
|
|
|
dest: "/etc/cni/net.d/10-calico.conf"
|
2017-02-06 20:58:54 +08:00
|
|
|
owner: kube
|
2016-11-14 15:48:28 +08:00
|
|
|
|
2016-11-09 18:44:41 +08:00
|
|
|
- name: Calico | Create calico certs directory
|
|
|
|
file:
|
|
|
|
dest: "{{ calico_cert_dir }}"
|
|
|
|
state: directory
|
|
|
|
mode: 0750
|
2017-02-06 20:58:54 +08:00
|
|
|
owner: root
|
|
|
|
group: root
|
2016-11-09 18:44:41 +08:00
|
|
|
|
|
|
|
- name: Calico | Link etcd certificates for calico-node
|
|
|
|
file:
|
|
|
|
src: "{{ etcd_cert_dir }}/{{ item.s }}"
|
|
|
|
dest: "{{ calico_cert_dir }}/{{ item.d }}"
|
|
|
|
state: hard
|
2016-12-08 00:03:04 +08:00
|
|
|
force: yes
|
2016-11-09 18:44:41 +08:00
|
|
|
with_items:
|
|
|
|
- {s: "ca.pem", d: "ca_cert.crt"}
|
2016-12-13 17:03:35 +08:00
|
|
|
- {s: "node-{{ inventory_hostname }}.pem", d: "cert.crt"}
|
|
|
|
- {s: "node-{{ inventory_hostname }}-key.pem", d: "key.pem"}
|
2016-11-09 18:44:41 +08:00
|
|
|
|
2016-07-04 23:16:18 +08:00
|
|
|
- name: Calico | Install calicoctl container script
|
|
|
|
template:
|
|
|
|
src: calicoctl-container.j2
|
|
|
|
dest: "{{ bin_dir }}/calicoctl"
|
|
|
|
mode: 0755
|
|
|
|
owner: root
|
|
|
|
group: root
|
2016-01-22 23:37:07 +08:00
|
|
|
changed_when: false
|
2016-07-04 23:16:18 +08:00
|
|
|
notify: restart calico-node
|
2015-10-04 04:19:50 +08:00
|
|
|
|
2016-08-10 17:58:10 +08:00
|
|
|
- name: Calico | Copy cni plugins from hyperkube
|
2016-12-23 22:44:44 +08:00
|
|
|
command: "{{ docker_bin_dir }}/docker run --rm -v /opt/cni/bin:/cnibindir {{ hyperkube_image_repo }}:{{ hyperkube_image_tag }} /usr/bin/rsync -a /opt/cni/bin/ /cnibindir/"
|
2016-09-13 20:36:01 +08:00
|
|
|
register: cni_task_result
|
|
|
|
until: cni_task_result.rc == 0
|
|
|
|
retries: 4
|
2016-09-15 17:23:27 +08:00
|
|
|
delay: "{{ retry_stagger | random + 3 }}"
|
2016-08-10 17:58:10 +08:00
|
|
|
changed_when: false
|
2016-12-08 21:36:00 +08:00
|
|
|
tags: [hyperkube, upgrade]
|
2016-01-30 23:04:47 +08:00
|
|
|
|
2016-11-10 18:57:06 +08:00
|
|
|
- name: Calico | Copy cni plugins from calico/cni container
|
2016-12-23 22:44:44 +08:00
|
|
|
command: "{{ docker_bin_dir }}/docker run --rm -v /opt/cni/bin:/cnibindir {{ calico_cni_image_repo }}:{{ calico_cni_image_tag }} sh -c 'cp -a /opt/cni/bin/* /cnibindir/'"
|
2016-11-10 18:57:06 +08:00
|
|
|
register: cni_task_result
|
|
|
|
until: cni_task_result.rc == 0
|
|
|
|
retries: 4
|
|
|
|
delay: "{{ retry_stagger | random + 3 }}"
|
2016-09-22 23:34:11 +08:00
|
|
|
changed_when: false
|
2016-10-09 01:19:25 +08:00
|
|
|
when: "{{ overwrite_hyperkube_cni|bool }}"
|
2016-12-08 21:36:00 +08:00
|
|
|
tags: [hyperkube, upgrade]
|
2016-09-22 23:34:11 +08:00
|
|
|
|
2016-01-25 09:01:25 +08:00
|
|
|
- name: Calico | wait for etcd
|
2016-11-09 18:44:41 +08:00
|
|
|
uri: url=https://localhost:2379/health validate_certs=no
|
2016-07-19 21:45:37 +08:00
|
|
|
register: result
|
2016-11-09 18:31:12 +08:00
|
|
|
until: result.status == 200 or result.status == 401
|
2016-07-19 21:45:37 +08:00
|
|
|
retries: 10
|
|
|
|
delay: 5
|
2016-11-09 18:31:12 +08:00
|
|
|
delegate_to: "{{groups['etcd'][0]}}"
|
|
|
|
run_once: true
|
2016-01-09 17:45:50 +08:00
|
|
|
|
2015-12-20 23:51:14 +08:00
|
|
|
- name: Calico | Check if calico network pool has already been configured
|
2016-11-09 18:31:12 +08:00
|
|
|
command: |-
|
|
|
|
curl \
|
|
|
|
--cacert {{ etcd_cert_dir }}/ca.pem \
|
2016-12-13 17:03:35 +08:00
|
|
|
--cert {{ etcd_cert_dir}}/admin-{{ groups['etcd'][0] }}.pem \
|
|
|
|
--key {{ etcd_cert_dir }}/admin-{{ groups['etcd'][0] }}-key.pem \
|
2016-11-09 18:31:12 +08:00
|
|
|
https://localhost:2379/v2/keys/calico/v1/ipam/v4/pool
|
2015-12-20 23:51:14 +08:00
|
|
|
register: calico_conf
|
2016-11-09 18:31:12 +08:00
|
|
|
delegate_to: "{{groups['etcd'][0]}}"
|
2015-12-20 23:51:14 +08:00
|
|
|
run_once: true
|
2016-12-08 21:36:00 +08:00
|
|
|
tags: facts
|
2015-12-20 23:51:14 +08:00
|
|
|
|
2016-11-08 04:37:12 +08:00
|
|
|
- name: Calico | Configure calico network pool
|
|
|
|
shell: >
|
|
|
|
echo '{
|
|
|
|
"kind": "ipPool",
|
|
|
|
"spec": {"disabled": false, "ipip": {"enabled": {{ cloud_provider is defined or ipip }}},
|
|
|
|
"nat-outgoing": {{ nat_outgoing|default(false) and not peer_with_router|default(false) }}},
|
|
|
|
"apiVersion": "v1",
|
|
|
|
"metadata": {"cidr": "{{ kube_pods_subnet }}"}
|
|
|
|
}'
|
|
|
|
| {{ bin_dir }}/calicoctl create -f -
|
|
|
|
environment:
|
|
|
|
NO_DEFAULT_POOLS: true
|
|
|
|
run_once: true
|
2016-11-24 21:56:33 +08:00
|
|
|
when: not legacy_calicoctl and
|
|
|
|
("Key not found" in calico_conf.stdout or "nodes" not in calico_conf.stdout)
|
2016-11-08 04:37:12 +08:00
|
|
|
|
|
|
|
- name: Calico (old) | Define ipip pool argument
|
2016-02-21 19:42:23 +08:00
|
|
|
run_once: true
|
2016-07-21 19:05:40 +08:00
|
|
|
set_fact:
|
|
|
|
ipip_arg: "--ipip"
|
2016-11-08 04:37:12 +08:00
|
|
|
when: (legacy_calicoctl and
|
|
|
|
cloud_provider is defined or ipip)
|
2016-12-08 21:36:00 +08:00
|
|
|
tags: facts
|
2016-02-21 19:42:23 +08:00
|
|
|
|
2016-11-08 04:37:12 +08:00
|
|
|
- name: Calico (old) | Define nat-outgoing pool argument
|
2016-01-29 21:07:21 +08:00
|
|
|
run_once: true
|
2016-07-21 19:05:40 +08:00
|
|
|
set_fact:
|
|
|
|
nat_arg: "--nat-outgoing"
|
2016-11-08 04:37:12 +08:00
|
|
|
when: (legacy_calicoctl and
|
|
|
|
nat_outgoing|default(false) and not peer_with_router|default(false))
|
2016-12-08 21:36:00 +08:00
|
|
|
tags: facts
|
2016-01-29 21:07:21 +08:00
|
|
|
|
2016-11-08 04:37:12 +08:00
|
|
|
- name: Calico (old) | Define calico pool task name
|
2015-12-11 18:42:25 +08:00
|
|
|
run_once: true
|
2016-07-21 19:05:40 +08:00
|
|
|
set_fact:
|
|
|
|
pool_task_name: "with options {{ ipip_arg|default('') }} {{ nat_arg|default('') }}"
|
2016-11-08 04:37:12 +08:00
|
|
|
when: (legacy_calicoctl and ipip_arg|default(false) or nat_arg|default(false))
|
2016-12-08 21:36:00 +08:00
|
|
|
tags: facts
|
2016-07-21 19:05:40 +08:00
|
|
|
|
2016-11-08 04:37:12 +08:00
|
|
|
- name: Calico (old) | Configure calico network pool {{ pool_task_name|default('') }}
|
2016-07-21 19:05:40 +08:00
|
|
|
command: "{{ bin_dir}}/calicoctl pool add {{ kube_pods_subnet }} {{ ipip_arg|default('') }} {{ nat_arg|default('') }}"
|
2016-08-31 17:53:33 +08:00
|
|
|
environment:
|
|
|
|
NO_DEFAULT_POOLS: true
|
2015-12-11 18:42:25 +08:00
|
|
|
run_once: true
|
2016-11-24 21:56:33 +08:00
|
|
|
when: legacy_calicoctl and
|
|
|
|
("Key not found" in calico_conf.stdout or "nodes" not in calico_conf.stdout)
|
2015-12-20 23:51:14 +08:00
|
|
|
|
|
|
|
- name: Calico | Get calico configuration from etcd
|
2016-11-09 18:31:12 +08:00
|
|
|
command: |-
|
2016-11-09 18:44:41 +08:00
|
|
|
curl \
|
|
|
|
--cacert {{ etcd_cert_dir }}/ca.pem \
|
2016-12-13 17:03:35 +08:00
|
|
|
--cert {{ etcd_cert_dir}}/admin-{{ groups['etcd'][0] }}.pem \
|
|
|
|
--key {{ etcd_cert_dir }}/admin-{{ groups['etcd'][0] }}-key.pem \
|
2016-11-09 18:44:41 +08:00
|
|
|
https://localhost:2379/v2/keys/calico/v1/ipam/v4/pool
|
2016-11-09 18:31:12 +08:00
|
|
|
register: calico_pools_raw
|
|
|
|
delegate_to: "{{groups['etcd'][0]}}"
|
|
|
|
run_once: true
|
|
|
|
|
|
|
|
- set_fact:
|
|
|
|
calico_pools: "{{ calico_pools_raw.stdout | from_json }}"
|
2015-12-20 23:51:14 +08:00
|
|
|
run_once: true
|
2016-12-08 21:36:00 +08:00
|
|
|
tags: facts
|
2015-12-20 23:51:14 +08:00
|
|
|
|
|
|
|
- name: Calico | Check if calico pool is properly configured
|
|
|
|
fail:
|
|
|
|
msg: 'Only one network pool must be configured and it must be the subnet {{ kube_pods_subnet }}.
|
|
|
|
Please erase calico configuration and run the playbook again ("etcdctl rm --recursive /calico/v1/ipam/v4/pool")'
|
2016-11-09 18:31:12 +08:00
|
|
|
when: ( calico_pools['node']['nodes'] | length > 1 ) or
|
|
|
|
( not calico_pools['node']['nodes'][0]['key'] | search(".*{{ kube_pods_subnet | ipaddr('network') }}.*") )
|
2015-12-20 23:51:14 +08:00
|
|
|
run_once: true
|
2016-12-08 21:36:00 +08:00
|
|
|
tags: facts
|
2015-12-11 18:42:25 +08:00
|
|
|
|
2016-12-09 00:48:54 +08:00
|
|
|
- name: Calico | Set global as_num
|
|
|
|
command: "{{ bin_dir}}/calicoctl config set asNumber {{ global_as_num }}"
|
|
|
|
run_once: true
|
|
|
|
when: not legacy_calicoctl
|
|
|
|
|
|
|
|
- name: Calico (old) | Set global as_num
|
|
|
|
command: "{{ bin_dir}}/calicoctl bgp default-node-as {{ global_as_num }}"
|
|
|
|
run_once: true
|
|
|
|
when: legacy_calicoctl
|
|
|
|
|
2016-12-05 19:06:16 +08:00
|
|
|
- name: Calico (old) | Write calico-node systemd init file
|
|
|
|
template: src=calico-node.service.legacy.j2 dest=/etc/systemd/system/calico-node.service
|
2017-01-02 19:14:03 +08:00
|
|
|
when: legacy_calicoctl
|
2016-12-05 19:06:16 +08:00
|
|
|
notify: restart calico-node
|
|
|
|
|
|
|
|
- name: Calico | Write calico.env for systemd init file
|
|
|
|
template: src=calico.env.j2 dest=/etc/calico/calico.env
|
2017-01-02 19:14:03 +08:00
|
|
|
when: not legacy_calicoctl
|
2016-12-05 19:06:16 +08:00
|
|
|
notify: restart calico-node
|
|
|
|
|
2015-10-15 15:40:02 +08:00
|
|
|
- name: Calico | Write calico-node systemd init file
|
2016-01-30 23:04:47 +08:00
|
|
|
template: src=calico-node.service.j2 dest=/etc/systemd/system/calico-node.service
|
2017-01-02 19:14:03 +08:00
|
|
|
when: not legacy_calicoctl
|
2016-01-04 21:24:29 +08:00
|
|
|
notify: restart calico-node
|
2015-11-20 21:04:13 +08:00
|
|
|
|
2016-12-13 17:03:35 +08:00
|
|
|
- name: Calico | Restart calico-node if secrets changed
|
|
|
|
command: /bin/true
|
|
|
|
when: secret_changed|default(false) or etcd_secret_changed|default(false)
|
|
|
|
notify: restart calico-node
|
|
|
|
|
2016-01-25 09:01:25 +08:00
|
|
|
- meta: flush_handlers
|
|
|
|
|
2015-10-15 15:40:02 +08:00
|
|
|
- name: Calico | Enable calico-node
|
2016-01-30 23:04:47 +08:00
|
|
|
service:
|
|
|
|
name: calico-node
|
|
|
|
state: started
|
|
|
|
enabled: yes
|
2016-01-09 17:45:50 +08:00
|
|
|
|
|
|
|
- name: Calico | Disable node mesh
|
2016-11-08 04:37:12 +08:00
|
|
|
shell: "{{ bin_dir }}/calicoctl config set nodeToNodeMesh off"
|
2016-12-09 00:48:54 +08:00
|
|
|
when: ((peer_with_router|default(false) or peer_with_calico_rr|default(false))
|
2017-01-20 18:38:57 +08:00
|
|
|
and inventory_hostname in groups['k8s-cluster']
|
2016-12-09 00:48:54 +08:00
|
|
|
and not legacy_calicoctl)
|
2016-12-06 20:56:34 +08:00
|
|
|
run_once: true
|
2016-01-09 17:45:50 +08:00
|
|
|
|
|
|
|
- name: Calico | Configure peering with router(s)
|
2016-11-08 04:37:12 +08:00
|
|
|
shell: >
|
|
|
|
echo '{
|
2016-12-06 20:56:34 +08:00
|
|
|
"kind": "bgpPeer",
|
|
|
|
"spec": {"asNumber": "{{ item.as }}"},
|
2016-11-08 04:37:12 +08:00
|
|
|
"apiVersion": "v1",
|
2016-12-06 20:56:34 +08:00
|
|
|
"metadata": {"node": "{{ inventory_hostname }}", "scope": "node", "peerIP": "{{ item.router_id }}"}
|
2016-11-08 04:37:12 +08:00
|
|
|
}'
|
|
|
|
| {{ bin_dir }}/calicoctl create -f -
|
2016-12-06 20:56:34 +08:00
|
|
|
with_items: "{{ peers|default([]) }}"
|
2016-11-08 04:37:12 +08:00
|
|
|
when: (not legacy_calicoctl and
|
2017-01-20 18:38:57 +08:00
|
|
|
peer_with_router|default(false) and inventory_hostname in groups['k8s-cluster'])
|
2016-11-08 04:37:12 +08:00
|
|
|
|
2016-12-09 00:48:54 +08:00
|
|
|
- name: Calico | Configure peering with route reflectors
|
|
|
|
shell: >
|
|
|
|
echo '{
|
|
|
|
"kind": "bgpPeer",
|
|
|
|
"spec": {"asNumber": "{{ local_as | default(global_as_num)}}"},
|
|
|
|
"apiVersion": "v1",
|
|
|
|
"metadata": {"node": "{{ inventory_hostname }}",
|
|
|
|
"scope": "node",
|
|
|
|
"peerIP": "{{ hostvars[item]["calico_rr_ip"]|default(hostvars[item]["ip"]) }}"}
|
|
|
|
}'
|
|
|
|
| {{ bin_dir }}/calicoctl create --skip-exists -f -
|
|
|
|
with_items: "{{ groups['calico-rr'] | default([]) }}"
|
|
|
|
when: (not legacy_calicoctl and
|
2017-01-20 18:38:57 +08:00
|
|
|
peer_with_calico_rr|default(false) and inventory_hostname in groups['k8s-cluster']
|
2016-12-09 00:48:54 +08:00
|
|
|
and hostvars[item]['cluster_id'] == cluster_id)
|
|
|
|
|
2016-11-08 04:37:12 +08:00
|
|
|
- name: Calico (old) | Disable node mesh
|
|
|
|
shell: "{{ bin_dir }}/calicoctl bgp node-mesh off"
|
2016-12-09 00:48:54 +08:00
|
|
|
when: ((peer_with_router|default(false) or peer_with_calico_rr|default(false))
|
2017-01-20 18:38:57 +08:00
|
|
|
and inventory_hostname in groups['k8s-cluster']
|
2016-12-09 00:48:54 +08:00
|
|
|
and legacy_calicoctl)
|
2016-12-06 20:56:34 +08:00
|
|
|
run_once: true
|
2016-11-08 04:37:12 +08:00
|
|
|
|
|
|
|
- name: Calico (old) | Configure peering with router(s)
|
2016-02-20 01:48:53 +08:00
|
|
|
shell: "{{ bin_dir }}/calicoctl node bgp peer add {{ item.router_id }} as {{ item.as }}"
|
2016-12-06 20:56:34 +08:00
|
|
|
with_items: "{{ peers|default([]) }}"
|
2016-11-08 04:37:12 +08:00
|
|
|
when: (legacy_calicoctl and
|
2017-01-20 18:38:57 +08:00
|
|
|
peer_with_router|default(false) and inventory_hostname in groups['k8s-cluster'])
|
2016-12-09 00:48:54 +08:00
|
|
|
|
|
|
|
- name: Calico (old) | Configure peering with route reflectors
|
|
|
|
shell: "{{ bin_dir }}/calicoctl node bgp peer add {{ hostvars[item]['calico_rr_ip']|default(hostvars[item]['ip']) }} as {{ local_as | default(global_as_num) }}"
|
|
|
|
with_items: "{{ groups['calico-rr'] | default([]) }}"
|
|
|
|
when: (legacy_calicoctl and
|
2017-01-20 18:38:57 +08:00
|
|
|
peer_with_calico_rr|default(false) and inventory_hostname in groups['k8s-cluster']
|
2016-12-09 00:48:54 +08:00
|
|
|
and hostvars[item]['cluster_id'] == cluster_id)
|