2018-08-23 14:17:18 +00:00
|
|
|
---
|
2019-04-15 11:24:04 +00:00
|
|
|
- name: Calico | Copy calicoctl binary from download dir
|
|
|
|
copy:
|
|
|
|
src: "{{ local_release_dir }}/calicoctl"
|
|
|
|
dest: "{{ bin_dir }}/calicoctl"
|
|
|
|
mode: 0755
|
|
|
|
remote_src: yes
|
|
|
|
|
2018-08-23 14:17:18 +00:00
|
|
|
- name: Calico | Write Calico cni config
|
|
|
|
template:
|
|
|
|
src: "cni-calico.conflist.j2"
|
2019-01-28 19:03:49 +00:00
|
|
|
dest: "/etc/cni/net.d/{% if calico_version is version('v3.3.0', '>=') %}calico.conflist.template{% else %}10-calico.conflist{% endif %}"
|
2018-08-23 14:17:18 +00:00
|
|
|
owner: kube
|
|
|
|
|
|
|
|
- name: Calico | Create calico certs directory
|
|
|
|
file:
|
|
|
|
dest: "{{ calico_cert_dir }}"
|
|
|
|
state: directory
|
|
|
|
mode: 0750
|
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
|
|
|
|
- name: Calico | Link etcd certificates for calico-node
|
|
|
|
file:
|
|
|
|
src: "{{ etcd_cert_dir }}/{{ item.s }}"
|
|
|
|
dest: "{{ calico_cert_dir }}/{{ item.d }}"
|
|
|
|
state: hard
|
|
|
|
force: yes
|
|
|
|
with_items:
|
2019-04-11 19:52:43 +00:00
|
|
|
- {s: "ca.pem", d: "ca_cert.crt"}
|
|
|
|
- {s: "node-{{ inventory_hostname }}.pem", d: "cert.crt"}
|
|
|
|
- {s: "node-{{ inventory_hostname }}-key.pem", d: "key.pem"}
|
2018-08-23 14:17:18 +00:00
|
|
|
|
2019-04-15 11:24:04 +00:00
|
|
|
- name: Calico | Install calicoctl wrapper script
|
2018-08-23 14:17:18 +00:00
|
|
|
template:
|
2019-04-15 11:24:04 +00:00
|
|
|
src: calicoctl.sh.j2
|
|
|
|
dest: "{{ bin_dir }}/calicoctl.sh"
|
2018-08-23 14:17:18 +00:00
|
|
|
mode: 0755
|
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
|
|
|
|
- name: Calico | wait for etcd
|
|
|
|
uri:
|
|
|
|
url: "{{ etcd_access_addresses.split(',') | first }}/health"
|
|
|
|
validate_certs: no
|
|
|
|
client_cert: "{{ etcd_cert_dir }}/node-{{ inventory_hostname }}.pem"
|
|
|
|
client_key: "{{ etcd_cert_dir }}/node-{{ inventory_hostname }}-key.pem"
|
|
|
|
register: result
|
|
|
|
until: result.status == 200 or result.status == 401
|
|
|
|
retries: 10
|
|
|
|
delay: 5
|
|
|
|
run_once: true
|
|
|
|
|
|
|
|
- name: Calico | Check if calico network pool has already been configured
|
|
|
|
shell: >
|
2019-04-15 11:24:04 +00:00
|
|
|
{{ bin_dir }}/calicoctl.sh get ippool | grep -w "{{ calico_pool_cidr | default(kube_pods_subnet) }}" | wc -l
|
2018-08-23 14:17:18 +00:00
|
|
|
register: calico_conf
|
|
|
|
retries: 4
|
|
|
|
delay: "{{ retry_stagger | random + 3 }}"
|
|
|
|
delegate_to: "{{ groups['kube-master'][0] }}"
|
|
|
|
run_once: true
|
2019-02-26 04:09:30 +00:00
|
|
|
changed_when: false
|
2018-08-23 14:17:18 +00:00
|
|
|
|
2019-01-31 21:39:13 +00:00
|
|
|
- name: Calico | Ensure that calico_pool_cidr is within kube_pods_subnet when defined
|
|
|
|
assert:
|
|
|
|
that: "[calico_pool_cidr] | ipaddr(kube_pods_subnet) | length == 1"
|
|
|
|
msg: "{{ calico_pool_cidr }} is not within or equal to {{ kube_pods_subnet }}"
|
|
|
|
delegate_to: localhost
|
|
|
|
run_once: true
|
|
|
|
when:
|
|
|
|
- 'calico_conf.stdout == "0"'
|
|
|
|
- calico_pool_cidr is defined
|
|
|
|
|
2019-03-06 20:42:48 +00:00
|
|
|
- name: Calico | Configure calico network pool (v3.0.0 <= version < v3.3.0)
|
2018-08-23 14:17:18 +00:00
|
|
|
shell: >
|
|
|
|
echo "
|
|
|
|
{ "kind": "IPPool",
|
|
|
|
"apiVersion": "projectcalico.org/v3",
|
|
|
|
"metadata": {
|
|
|
|
"name": "{{ calico_pool_name }}",
|
|
|
|
},
|
|
|
|
"spec": {
|
2019-01-31 21:39:13 +00:00
|
|
|
"cidr": "{{ calico_pool_cidr | default(kube_pods_subnet) }}",
|
2018-09-04 12:56:53 +00:00
|
|
|
"ipipMode": "{{ ipip_mode }}",
|
2019-04-15 11:24:04 +00:00
|
|
|
"natOutgoing": {{ nat_outgoing|default(false) and not peer_with_router|default(false) }} }} " | {{ bin_dir }}/calicoctl.sh create -f -
|
2018-08-23 14:17:18 +00:00
|
|
|
run_once: true
|
|
|
|
delegate_to: "{{ groups['kube-master'][0] }}"
|
|
|
|
when:
|
2018-09-11 12:14:10 +00:00
|
|
|
- 'calico_conf.stdout == "0"'
|
2018-10-16 22:33:30 +00:00
|
|
|
- calico_version is version("v3.0.0", ">=")
|
2019-03-06 20:42:48 +00:00
|
|
|
- calico_version is version("v3.3.0", "<")
|
|
|
|
|
|
|
|
- name: Calico | Configure calico network pool (version >= v3.3.0)
|
|
|
|
shell: >
|
|
|
|
echo "
|
|
|
|
{ "kind": "IPPool",
|
|
|
|
"apiVersion": "projectcalico.org/v3",
|
|
|
|
"metadata": {
|
|
|
|
"name": "{{ calico_pool_name }}",
|
|
|
|
},
|
|
|
|
"spec": {
|
|
|
|
"blockSize": "{{ kube_network_node_prefix }}",
|
|
|
|
"cidr": "{{ calico_pool_cidr | default(kube_pods_subnet) }}",
|
|
|
|
"ipipMode": "{{ ipip_mode }}",
|
2019-04-15 11:24:04 +00:00
|
|
|
"natOutgoing": {{ nat_outgoing|default(false) and not peer_with_router|default(false) }} }} " | {{ bin_dir }}/calicoctl.sh create -f -
|
2019-03-06 20:42:48 +00:00
|
|
|
run_once: true
|
|
|
|
delegate_to: "{{ groups['kube-master'][0] }}"
|
|
|
|
when:
|
|
|
|
- 'calico_conf.stdout == "0"'
|
|
|
|
- calico_version is version("v3.3.0", ">=")
|
2018-09-11 12:14:10 +00:00
|
|
|
|
|
|
|
- name: Calico | Configure calico network pool (legacy)
|
|
|
|
shell: >
|
|
|
|
echo '
|
|
|
|
{ "kind": "ipPool",
|
|
|
|
"spec": {"disabled": false, "ipip": {"enabled": {{ ipip }}, "mode": "{{ ipip_mode|lower }}"},
|
|
|
|
"nat-outgoing": {{ nat_outgoing|default(false) and not peer_with_router|default(false) }}},
|
|
|
|
"apiVersion": "v1",
|
2019-01-31 21:39:13 +00:00
|
|
|
"metadata": {"cidr": "{{ calico_pool_cidr | default(kube_pods_subnet) }}"}
|
2019-04-15 11:24:04 +00:00
|
|
|
}' | {{ bin_dir }}/calicoctl.sh apply -f -
|
2018-09-11 12:14:10 +00:00
|
|
|
environment:
|
|
|
|
NO_DEFAULT_POOLS: true
|
|
|
|
run_once: true
|
|
|
|
delegate_to: "{{ groups['kube-master'][0] }}"
|
|
|
|
when:
|
2018-08-23 14:17:18 +00:00
|
|
|
- 'calico_conf.stdout == "0"'
|
2018-10-16 22:33:30 +00:00
|
|
|
- calico_version is version("v3.0.0", "<")
|
2018-08-23 14:17:18 +00:00
|
|
|
|
|
|
|
- name: "Determine nodeToNodeMesh needed state"
|
|
|
|
set_fact:
|
|
|
|
nodeToNodeMeshEnabled: "false"
|
|
|
|
when:
|
|
|
|
- peer_with_router|default(false) or peer_with_calico_rr|default(false)
|
|
|
|
- inventory_hostname in groups['k8s-cluster']
|
|
|
|
run_once: yes
|
|
|
|
|
|
|
|
- name: Calico | Set global as_num
|
|
|
|
shell: >
|
|
|
|
echo '
|
|
|
|
{ "kind": "BGPConfiguration",
|
|
|
|
"apiVersion": "projectcalico.org/v3",
|
|
|
|
"metadata": {
|
|
|
|
"name": "default",
|
|
|
|
},
|
|
|
|
"spec": {
|
|
|
|
"logSeverityScreen": "Info",
|
|
|
|
"nodeToNodeMeshEnabled": {{ nodeToNodeMeshEnabled|default('true') }} ,
|
2019-04-15 11:24:04 +00:00
|
|
|
"asNumber": {{ global_as_num }} }} ' | {{ bin_dir }}/calicoctl.sh create --skip-exists -f -
|
2018-08-23 14:17:18 +00:00
|
|
|
run_once: true
|
|
|
|
delegate_to: "{{ groups['kube-master'][0] }}"
|
2018-09-11 12:14:10 +00:00
|
|
|
when:
|
2018-10-16 22:33:30 +00:00
|
|
|
- calico_version is version('v3.0.0', '>=')
|
2018-09-13 15:05:10 +00:00
|
|
|
|
2018-09-11 12:14:10 +00:00
|
|
|
- name: Calico | Set global as_num (legacy)
|
2019-04-15 11:24:04 +00:00
|
|
|
command: "{{ bin_dir}}/calicoctl.sh config set asNumber {{ global_as_num }}"
|
2018-09-11 12:14:10 +00:00
|
|
|
run_once: true
|
|
|
|
when:
|
2018-10-16 22:33:30 +00:00
|
|
|
- calico_version is version('v3.0.0', '<')
|
2018-09-11 12:14:10 +00:00
|
|
|
|
|
|
|
- name: Calico | Disable node mesh (legacy)
|
2019-04-15 11:24:04 +00:00
|
|
|
command: "{{ bin_dir }}/calicoctl.sh config set nodeToNodeMesh off"
|
2018-09-11 12:14:10 +00:00
|
|
|
run_once: yes
|
|
|
|
when:
|
2018-10-16 22:33:30 +00:00
|
|
|
- calico_version is version('v3.0.0', '<')
|
2018-09-11 12:14:10 +00:00
|
|
|
- nodeToMeshEnabled|default(True)
|
2018-08-23 14:17:18 +00:00
|
|
|
|
2018-10-16 06:44:49 +00:00
|
|
|
- name: Calico | Configure node asNumber for per node peering
|
|
|
|
shell: >
|
|
|
|
echo '{
|
|
|
|
"apiVersion": "projectcalico.org/v3",
|
|
|
|
"kind": "Node",
|
|
|
|
"metadata": {
|
|
|
|
"name": "{{ inventory_hostname }}"
|
|
|
|
},
|
|
|
|
"spec": {
|
|
|
|
"bgp": {
|
|
|
|
"asNumber": "{{ local_as }}"
|
|
|
|
},
|
|
|
|
"orchRefs":[{"nodeName":"{{ inventory_hostname }}","orchestrator":"k8s"}]
|
2019-04-15 11:24:04 +00:00
|
|
|
}}' | {{ bin_dir }}/calicoctl.sh create --skip-exists -f -
|
2018-10-16 06:44:49 +00:00
|
|
|
retries: 4
|
|
|
|
delay: "{{ retry_stagger | random + 3 }}"
|
|
|
|
when:
|
2018-10-16 22:33:30 +00:00
|
|
|
- calico_version is version('v3.0.0', '>=')
|
2018-10-16 06:44:49 +00:00
|
|
|
- peer_with_router|default(false)
|
|
|
|
- inventory_hostname in groups['k8s-cluster']
|
|
|
|
- local_as is defined
|
|
|
|
- groups['calico-rr'] | default([]) | length == 0
|
|
|
|
|
|
|
|
- name: Calico | Configure node asNumber for per node peering (legacy)
|
|
|
|
shell: >
|
|
|
|
echo '{
|
|
|
|
"apiVersion": "v1",
|
|
|
|
"kind": "node",
|
|
|
|
"metadata": {
|
|
|
|
"name": "{{ inventory_hostname }}"
|
|
|
|
},
|
|
|
|
"spec": {
|
|
|
|
"bgp": {
|
|
|
|
"asNumber": "{{ local_as }}"
|
|
|
|
},
|
|
|
|
"orchRefs":[{"nodeName":"{{ inventory_hostname }}","orchestrator":"k8s"}]
|
2019-04-15 11:24:04 +00:00
|
|
|
}}' | {{ bin_dir }}/calicoctl.sh create --skip-exists -f -
|
2018-10-16 06:44:49 +00:00
|
|
|
retries: 4
|
|
|
|
delay: "{{ retry_stagger | random + 3 }}"
|
|
|
|
when:
|
2018-10-16 22:33:30 +00:00
|
|
|
- calico_version is version('v3.0.0', '<')
|
2018-10-16 06:44:49 +00:00
|
|
|
- peer_with_router|default(false)
|
|
|
|
- inventory_hostname in groups['k8s-cluster']
|
|
|
|
- local_as is defined
|
|
|
|
- groups['calico-rr'] | default([]) | length == 0
|
|
|
|
|
2018-10-16 22:32:26 +00:00
|
|
|
- name: Calico | Configure peering with router(s) at node scope
|
2018-08-23 14:17:18 +00:00
|
|
|
shell: >
|
|
|
|
echo '{
|
|
|
|
"apiVersion": "projectcalico.org/v3",
|
2018-09-17 20:22:28 +00:00
|
|
|
"kind": "BGPPeer",
|
2018-08-23 14:17:18 +00:00
|
|
|
"metadata": {
|
2018-09-18 15:48:30 +00:00
|
|
|
"name": "{{ inventory_hostname }}-{{ item.router_id }}"
|
2018-08-23 14:17:18 +00:00
|
|
|
},
|
|
|
|
"spec": {
|
|
|
|
"asNumber": "{{ item.as }}",
|
|
|
|
"node": "{{ inventory_hostname }}",
|
|
|
|
"peerIP": "{{ item.router_id }}"
|
2019-04-15 11:24:04 +00:00
|
|
|
}}' | {{ bin_dir }}/calicoctl.sh create --skip-exists -f -
|
2018-08-23 14:17:18 +00:00
|
|
|
retries: 4
|
|
|
|
delay: "{{ retry_stagger | random + 3 }}"
|
|
|
|
with_items:
|
2018-10-24 05:19:50 +00:00
|
|
|
- "{{ peers|selectattr('scope','undefined')|list|default([]) | union(peers|selectattr('scope','defined')|selectattr('scope','equalto', 'node')|list|default([])) }}"
|
2018-08-23 14:17:18 +00:00
|
|
|
when:
|
2018-10-16 22:33:30 +00:00
|
|
|
- calico_version is version('v3.0.0', '>=')
|
2018-08-23 14:17:18 +00:00
|
|
|
- peer_with_router|default(false)
|
|
|
|
- inventory_hostname in groups['k8s-cluster']
|
|
|
|
|
2018-10-16 22:32:26 +00:00
|
|
|
- name: Calico | Configure peering with router(s) at node scope (legacy)
|
2018-09-06 12:49:06 +00:00
|
|
|
shell: >
|
|
|
|
echo '{
|
|
|
|
"kind": "bgpPeer",
|
|
|
|
"spec": {"asNumber": "{{ item.as }}"},
|
|
|
|
"apiVersion": "v1",
|
|
|
|
"metadata": {"node": "{{ inventory_hostname }}", "scope": "node", "peerIP": "{{ item.router_id }}"}
|
|
|
|
}'
|
2019-04-15 11:24:04 +00:00
|
|
|
| {{ bin_dir }}/calicoctl.sh create --skip-exists -f -
|
2018-09-06 12:49:06 +00:00
|
|
|
retries: 4
|
|
|
|
delay: "{{ retry_stagger | random + 3 }}"
|
2018-10-24 05:19:50 +00:00
|
|
|
with_items: "{{ peers|selectattr('scope','undefined')|list|default([]) | union(peers|selectattr('scope','defined')|selectattr('scope','equalto', 'node')|list|default([])) }}"
|
2018-10-16 22:32:26 +00:00
|
|
|
when:
|
|
|
|
- calico_version | version_compare('v3.0.0', '<')
|
|
|
|
- peer_with_router|default(false)
|
|
|
|
- inventory_hostname in groups['k8s-cluster']
|
|
|
|
|
|
|
|
- name: Calico | Configure peering with router(s) at global scope
|
|
|
|
shell: >
|
|
|
|
echo '{
|
|
|
|
"apiVersion": "projectcalico.org/v3",
|
|
|
|
"kind": "BGPPeer",
|
|
|
|
"metadata": {
|
|
|
|
"name": "global-{{ item.router_id }}"
|
|
|
|
},
|
|
|
|
"spec": {
|
|
|
|
"asNumber": "{{ item.as }}",
|
|
|
|
"peerIP": "{{ item.router_id }}"
|
2019-04-15 11:24:04 +00:00
|
|
|
}}' | {{ bin_dir }}/calicoctl.sh create --skip-exists -f -
|
2018-10-16 22:32:26 +00:00
|
|
|
retries: 4
|
|
|
|
delay: "{{ retry_stagger | random + 3 }}"
|
|
|
|
with_items:
|
2018-10-24 05:19:50 +00:00
|
|
|
- "{{ peers|selectattr('scope','defined')|selectattr('scope','equalto', 'global')|list|default([]) }}"
|
2018-10-16 22:32:26 +00:00
|
|
|
run_once: true
|
|
|
|
when:
|
|
|
|
- calico_version | version_compare('v3.0.0', '>=')
|
|
|
|
- peer_with_router|default(false)
|
|
|
|
- inventory_hostname in groups['k8s-cluster']
|
|
|
|
|
|
|
|
- name: Calico | Configure peering with router(s) at global scope (legacy)
|
|
|
|
shell: >
|
|
|
|
echo '{
|
|
|
|
"kind": "bgpPeer",
|
|
|
|
"spec": {"asNumber": "{{ item.as }}"},
|
|
|
|
"apiVersion": "v1",
|
|
|
|
"metadata": {"scope": "global", "peerIP": "{{ item.router_id }}"}
|
|
|
|
}'
|
2019-04-15 11:24:04 +00:00
|
|
|
| {{ bin_dir }}/calicoctl.sh create --skip-exists -f -
|
2018-10-16 22:32:26 +00:00
|
|
|
retries: 4
|
|
|
|
delay: "{{ retry_stagger | random + 3 }}"
|
2018-10-24 05:19:50 +00:00
|
|
|
with_items: "{{ peers|selectattr('scope','defined')|selectattr('scope','equalto', 'global')|default([]) }}"
|
2018-10-16 22:32:26 +00:00
|
|
|
run_once: true
|
2018-09-06 12:49:06 +00:00
|
|
|
when:
|
2018-10-16 22:33:30 +00:00
|
|
|
- calico_version is version('v3.0.0', '<')
|
2018-09-12 14:03:55 +00:00
|
|
|
- peer_with_router|default(false)
|
|
|
|
- inventory_hostname in groups['k8s-cluster']
|
2018-09-06 12:49:06 +00:00
|
|
|
|
2018-08-23 14:17:18 +00:00
|
|
|
- name: Calico | Configure peering with route reflectors
|
|
|
|
shell: >
|
|
|
|
echo '{
|
|
|
|
"apiVersion": "projectcalico.org/v3",
|
2018-09-17 20:22:28 +00:00
|
|
|
"kind": "BGPPeer",
|
2018-08-23 14:17:18 +00:00
|
|
|
"metadata": {
|
2019-03-05 11:04:39 +00:00
|
|
|
"name": "{{ inventory_hostname }}-{{ hostvars[item]["calico_rr_ip"]|default(hostvars[item]["ip"])|default(fallback_ips[item]) }}"
|
2018-08-23 14:17:18 +00:00
|
|
|
},
|
|
|
|
"spec": {
|
|
|
|
"asNumber": "{{ local_as | default(global_as_num)}}",
|
|
|
|
"node": "{{ inventory_hostname }}",
|
2019-03-05 11:04:39 +00:00
|
|
|
"peerIP": "{{ hostvars[item]["calico_rr_ip"]|default(hostvars[item]["ip"])|default(fallback_ips[item]) }}"
|
2019-04-15 11:24:04 +00:00
|
|
|
}}' | {{ bin_dir }}/calicoctl.sh create --skip-exists -f -
|
2018-08-23 14:17:18 +00:00
|
|
|
retries: 4
|
|
|
|
delay: "{{ retry_stagger | random + 3 }}"
|
|
|
|
with_items:
|
|
|
|
- "{{ groups['calico-rr'] | default([]) }}"
|
|
|
|
when:
|
2018-10-16 22:33:30 +00:00
|
|
|
- calico_version is version('v3.0.0', '>=')
|
2018-09-06 12:49:06 +00:00
|
|
|
- peer_with_calico_rr|default(false)
|
2018-08-23 14:17:18 +00:00
|
|
|
- inventory_hostname in groups['k8s-cluster']
|
2018-09-06 12:49:06 +00:00
|
|
|
- hostvars[item]['cluster_id'] == cluster_id
|
|
|
|
|
|
|
|
- name: Calico | Configure peering with route reflectors (legacy)
|
|
|
|
shell: >
|
|
|
|
echo '{
|
|
|
|
"kind": "bgpPeer",
|
|
|
|
"spec": {"asNumber": "{{ local_as | default(global_as_num)}}"},
|
|
|
|
"apiVersion": "v1",
|
|
|
|
"metadata": {"node": "{{ inventory_hostname }}",
|
|
|
|
"scope": "node",
|
2019-03-05 11:04:39 +00:00
|
|
|
"peerIP": "{{ hostvars[item]["calico_rr_ip"]|default(hostvars[item]["ip"])|default(fallback_ips[item]) }}"}
|
2018-09-06 12:49:06 +00:00
|
|
|
}'
|
2019-04-15 11:24:04 +00:00
|
|
|
| {{ bin_dir }}/calicoctl.sh create --skip-exists -f -
|
2018-09-06 12:49:06 +00:00
|
|
|
retries: 4
|
|
|
|
delay: "{{ retry_stagger | random + 3 }}"
|
|
|
|
with_items: "{{ groups['calico-rr'] | default([]) }}"
|
|
|
|
when:
|
2018-10-16 22:33:30 +00:00
|
|
|
- calico_version is version('v3.0.0', '<')
|
2018-09-12 14:03:55 +00:00
|
|
|
- not calico_upgrade_enabled
|
|
|
|
- peer_with_calico_rr|default(false)
|
|
|
|
- hostvars[item]['cluster_id'] == cluster_id
|
2018-09-06 12:49:06 +00:00
|
|
|
|
2018-08-23 14:17:18 +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']
|
2018-09-04 12:56:53 +00:00
|
|
|
- rbac_enabled or item.type not in rbac_resources
|