2015-10-03 20:19:50 +00:00
|
|
|
---
|
2017-09-04 08:29:51 +00:00
|
|
|
- name: Calico | Disable calico-node service if it exists
|
|
|
|
service:
|
|
|
|
name: calico-node
|
|
|
|
state: stopped
|
|
|
|
enabled: yes
|
|
|
|
failed_when: false
|
2016-12-07 11:13:12 +00:00
|
|
|
|
2017-09-24 08:22:15 +00:00
|
|
|
- name: Calico | Get kubelet hostname
|
|
|
|
shell: >-
|
|
|
|
kubectl get node -o custom-columns='NAME:.metadata.name,INTERNAL-IP:.status.addresses[?(@.type=="InternalIP")].address'
|
|
|
|
| egrep "[[:space:]]{{ ansible_all_ipv4_addresses | join('[[:space:]]|[[:space:]]') }}[[:space:]]*$" | cut -d" " -f1
|
|
|
|
register: calico_kubelet_name
|
|
|
|
when: cloud_provider is defined
|
|
|
|
|
2016-11-14 07:48:28 +00:00
|
|
|
- name: Calico | Write Calico cni config
|
|
|
|
template:
|
|
|
|
src: "cni-calico.conf.j2"
|
|
|
|
dest: "/etc/cni/net.d/10-calico.conf"
|
2017-02-06 12:58:54 +00:00
|
|
|
owner: kube
|
2016-11-14 07:48:28 +00:00
|
|
|
|
2016-11-09 10:44:41 +00:00
|
|
|
- name: Calico | Create calico certs directory
|
|
|
|
file:
|
|
|
|
dest: "{{ calico_cert_dir }}"
|
|
|
|
state: directory
|
|
|
|
mode: 0750
|
2017-02-06 12:58:54 +00:00
|
|
|
owner: root
|
|
|
|
group: root
|
2016-11-09 10:44:41 +00: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-07 16:03:04 +00:00
|
|
|
force: yes
|
2016-11-09 10:44:41 +00:00
|
|
|
with_items:
|
|
|
|
- {s: "ca.pem", d: "ca_cert.crt"}
|
2016-12-13 09:03:35 +00:00
|
|
|
- {s: "node-{{ inventory_hostname }}.pem", d: "cert.crt"}
|
|
|
|
- {s: "node-{{ inventory_hostname }}-key.pem", d: "key.pem"}
|
2016-11-09 10:44:41 +00:00
|
|
|
|
2016-07-04 15:16:18 +00: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 15:37:07 +00:00
|
|
|
changed_when: false
|
2015-10-03 20:19:50 +00:00
|
|
|
|
2016-08-10 09:58:10 +00:00
|
|
|
- name: Calico | Copy cni plugins from hyperkube
|
2017-03-15 11:00:42 +00:00
|
|
|
command: "{{ docker_bin_dir }}/docker run --rm -v /opt/cni/bin:/cnibindir {{ hyperkube_image_repo }}:{{ hyperkube_image_tag }} /usr/bin/rsync -ac /opt/cni/bin/ /cnibindir/"
|
2016-09-13 12:36:01 +00:00
|
|
|
register: cni_task_result
|
|
|
|
until: cni_task_result.rc == 0
|
|
|
|
retries: 4
|
2016-09-15 09:23:27 +00:00
|
|
|
delay: "{{ retry_stagger | random + 3 }}"
|
2016-08-10 09:58:10 +00:00
|
|
|
changed_when: false
|
2016-12-08 13:36:00 +00:00
|
|
|
tags: [hyperkube, upgrade]
|
2016-01-30 15:04:47 +00:00
|
|
|
|
2016-11-10 10:57:06 +00:00
|
|
|
- name: Calico | Copy cni plugins from calico/cni container
|
2016-12-23 14:44:44 +00: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 10:57:06 +00:00
|
|
|
register: cni_task_result
|
|
|
|
until: cni_task_result.rc == 0
|
|
|
|
retries: 4
|
|
|
|
delay: "{{ retry_stagger | random + 3 }}"
|
2016-09-22 15:34:11 +00:00
|
|
|
changed_when: false
|
2017-04-26 12:11:13 +00:00
|
|
|
when: overwrite_hyperkube_cni|bool
|
2016-12-08 13:36:00 +00:00
|
|
|
tags: [hyperkube, upgrade]
|
2016-09-22 15:34:11 +00:00
|
|
|
|
2017-03-15 11:00:42 +00:00
|
|
|
- name: Calico | Set cni directory permissions
|
|
|
|
file:
|
|
|
|
path: /opt/cni/bin
|
|
|
|
state: directory
|
|
|
|
owner: kube
|
|
|
|
recurse: true
|
|
|
|
mode: 0755
|
|
|
|
|
2016-01-25 01:01:25 +00:00
|
|
|
- name: Calico | wait for etcd
|
2017-02-17 21:22:34 +00:00
|
|
|
uri:
|
|
|
|
url: https://localhost:2379/health
|
|
|
|
validate_certs: no
|
2016-07-19 13:45:37 +00:00
|
|
|
register: result
|
2016-11-09 10:31:12 +00:00
|
|
|
until: result.status == 200 or result.status == 401
|
2016-07-19 13:45:37 +00:00
|
|
|
retries: 10
|
|
|
|
delay: 5
|
2016-11-09 10:31:12 +00:00
|
|
|
delegate_to: "{{groups['etcd'][0]}}"
|
|
|
|
run_once: true
|
2016-01-09 09:45:50 +00:00
|
|
|
|
2015-12-20 15:51:14 +00:00
|
|
|
- name: Calico | Check if calico network pool has already been configured
|
2016-11-09 10:31:12 +00:00
|
|
|
command: |-
|
|
|
|
curl \
|
|
|
|
--cacert {{ etcd_cert_dir }}/ca.pem \
|
2016-12-13 09:03:35 +00:00
|
|
|
--cert {{ etcd_cert_dir}}/admin-{{ groups['etcd'][0] }}.pem \
|
|
|
|
--key {{ etcd_cert_dir }}/admin-{{ groups['etcd'][0] }}-key.pem \
|
2016-11-09 10:31:12 +00:00
|
|
|
https://localhost:2379/v2/keys/calico/v1/ipam/v4/pool
|
2015-12-20 15:51:14 +00:00
|
|
|
register: calico_conf
|
2016-11-09 10:31:12 +00:00
|
|
|
delegate_to: "{{groups['etcd'][0]}}"
|
2015-12-20 15:51:14 +00:00
|
|
|
run_once: true
|
2017-03-15 11:00:42 +00:00
|
|
|
changed_when: false
|
2015-12-20 15:51:14 +00:00
|
|
|
|
2016-11-07 20:37:12 +00:00
|
|
|
- name: Calico | Configure calico network pool
|
|
|
|
shell: >
|
|
|
|
echo '{
|
|
|
|
"kind": "ipPool",
|
2017-07-08 12:36:44 +00:00
|
|
|
"spec": {"disabled": false, "ipip": {"enabled": {{ ipip }}, "mode": "{{ ipip_mode }}"},
|
2016-11-07 20:37:12 +00:00
|
|
|
"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
|
2017-09-04 08:29:51 +00:00
|
|
|
when: ("Key not found" in calico_conf.stdout or "nodes" not in calico_conf.stdout)
|
2015-12-20 15:51:14 +00:00
|
|
|
|
|
|
|
- name: Calico | Get calico configuration from etcd
|
2016-11-09 10:31:12 +00:00
|
|
|
command: |-
|
2016-11-09 10:44:41 +00:00
|
|
|
curl \
|
|
|
|
--cacert {{ etcd_cert_dir }}/ca.pem \
|
2016-12-13 09:03:35 +00:00
|
|
|
--cert {{ etcd_cert_dir}}/admin-{{ groups['etcd'][0] }}.pem \
|
|
|
|
--key {{ etcd_cert_dir }}/admin-{{ groups['etcd'][0] }}-key.pem \
|
2016-11-09 10:44:41 +00:00
|
|
|
https://localhost:2379/v2/keys/calico/v1/ipam/v4/pool
|
2016-11-09 10:31:12 +00: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 15:51:14 +00:00
|
|
|
run_once: true
|
|
|
|
|
|
|
|
- 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 10:31:12 +00: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 15:51:14 +00:00
|
|
|
run_once: true
|
2015-12-11 10:42:25 +00:00
|
|
|
|
2016-12-08 16:48:54 +00:00
|
|
|
- name: Calico | Set global as_num
|
|
|
|
command: "{{ bin_dir}}/calicoctl config set asNumber {{ global_as_num }}"
|
|
|
|
run_once: true
|
2016-01-09 09:45:50 +00:00
|
|
|
|
|
|
|
- name: Calico | Disable node mesh
|
2016-11-07 20:37:12 +00:00
|
|
|
shell: "{{ bin_dir }}/calicoctl config set nodeToNodeMesh off"
|
2016-12-08 16:48:54 +00:00
|
|
|
when: ((peer_with_router|default(false) or peer_with_calico_rr|default(false))
|
2017-09-04 08:29:51 +00:00
|
|
|
and inventory_hostname in groups['k8s-cluster'])
|
2016-12-06 12:56:34 +00:00
|
|
|
run_once: true
|
2016-01-09 09:45:50 +00:00
|
|
|
|
|
|
|
- name: Calico | Configure peering with router(s)
|
2016-11-07 20:37:12 +00:00
|
|
|
shell: >
|
|
|
|
echo '{
|
2016-12-06 12:56:34 +00:00
|
|
|
"kind": "bgpPeer",
|
|
|
|
"spec": {"asNumber": "{{ item.as }}"},
|
2016-11-07 20:37:12 +00:00
|
|
|
"apiVersion": "v1",
|
2016-12-06 12:56:34 +00:00
|
|
|
"metadata": {"node": "{{ inventory_hostname }}", "scope": "node", "peerIP": "{{ item.router_id }}"}
|
2016-11-07 20:37:12 +00:00
|
|
|
}'
|
2017-05-25 19:29:18 +00:00
|
|
|
| {{ bin_dir }}/calicoctl create --skip-exists -f -
|
2016-12-06 12:56:34 +00:00
|
|
|
with_items: "{{ peers|default([]) }}"
|
2017-09-04 08:29:51 +00:00
|
|
|
when: peer_with_router|default(false) and inventory_hostname in groups['k8s-cluster']
|
2016-11-07 20:37:12 +00:00
|
|
|
|
2016-12-08 16:48:54 +00: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",
|
2016-12-27 15:39:00 +00:00
|
|
|
"peerIP": "{{ hostvars[item]["calico_rr_ip"]|default(hostvars[item]["ip"])|default(hostvars[item]["ansible_default_ipv4.address"]) }}"}
|
2016-12-08 16:48:54 +00:00
|
|
|
}'
|
|
|
|
| {{ bin_dir }}/calicoctl create --skip-exists -f -
|
|
|
|
with_items: "{{ groups['calico-rr'] | default([]) }}"
|
2017-09-04 08:29:51 +00:00
|
|
|
when: (peer_with_calico_rr|default(false) and inventory_hostname in groups['k8s-cluster']
|
2016-12-08 16:48:54 +00:00
|
|
|
and hostvars[item]['cluster_id'] == cluster_id)
|
|
|
|
|
2017-09-04 08:29:51 +00:00
|
|
|
- name: Calico | Create calico manifests
|
|
|
|
template:
|
|
|
|
src: "{{item.file}}.j2"
|
|
|
|
dest: "{{kube_config_dir}}/{{item.file}}"
|
|
|
|
with_items:
|
|
|
|
- {name: calico-config, file: calico-config.yml, type: cm}
|
|
|
|
- {name: calico-node, file: calico-node.yml, type: ds}
|
|
|
|
- {name: calico, file: calico-node-sa.yml, type: sa}
|
|
|
|
- {name: calico, file: calico-cr.yml, type: clusterrole}
|
|
|
|
- {name: calico, file: calico-crb.yml, type: clusterrolebinding}
|
|
|
|
register: calico_node_manifests
|
|
|
|
when:
|
|
|
|
- inventory_hostname in groups['kube-master']
|
|
|
|
- rbac_enabled or item.type not in rbac_resources
|