-
Notifications
You must be signed in to change notification settings - Fork 77
/
22_apply_network_plugin.yml
97 lines (88 loc) · 3.9 KB
/
22_apply_network_plugin.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
---
- name: Apply network plugin
hosts: vm_host
run_once: true
vars_files:
- vars/k8s_cluster.yml
tasks:
- name: Configure Calico
when: k8s.network.cni_plugin == 'calico'
block:
- name: Download Calico manifest.
ansible.builtin.get_url:
url: "{{ item.url }}"
dest: "{{ item.name }}"
mode: "0664"
loop:
- name: /tmp/{{ k8s.cluster_name | default('k8s-test', true) }}/calico-operator.yaml
url: "{{ cni_plugins.calico.calico_operator }}"
- name: /tmp/{{ k8s.cluster_name | default('k8s-test', true) }}/calico-crd.yaml
url: "{{ cni_plugins.calico.calico_crd }}"
- name: Apply custom CIDR to calico installation manifest
ansible.builtin.replace:
path: /tmp/{{ k8s.cluster_name | default('k8s-test', true) }}/calico-crd.yaml
regexp: 192.168.0.0\/16
replace: "{{ k8s.network.pod_cidr }}"
# - name: Temporary fix for non ascii char in Calico CRD (https://github.com/projectcalico/api/pull/46)
# ansible.builtin.replace:
# path: /tmp/{{ k8s.cluster_name | default('k8s-test', true) }}/calico-operator.yaml
# regexp: \’
# replace: ""
- name: Apply calico manifests to the cluster.
kubernetes.core.k8s:
state: present
src: "{{ item }}"
kubeconfig: "{{ workspace_directory.base_path }}/clusters/{{ k8s.cluster_name | default('k8s-test', true) }}/admin.kubeconfig"
wait: true
loop:
- /tmp/{{ k8s.cluster_name | default('k8s-test', true) }}/calico-operator.yaml
- /tmp/{{ k8s.cluster_name | default('k8s-test', true) }}/calico-crd.yaml
- name: Configure Cilium
when: k8s.network.cni_plugin == 'cilium'
block:
- name: Add helm chart repository for Cilium
kubernetes.core.helm_repository:
name: "{{ item.name }}"
repo_url: "{{ item.repo_url }}"
loop:
- name: "{{ cni_plugins.cilium.chart.name }}"
repo_url: "{{ cni_plugins.cilium.chart.url }}"
- name: Ensure Cilium helm chart is installed
kubernetes.core.helm:
name: cilium
chart_ref: "{{ cni_plugins.cilium.chart.ref }}"
kubeconfig: "{{ workspace_directory.base_path }}/clusters/{{ k8s.cluster_name | default('k8s-test', true) }}/admin.kubeconfig"
release_namespace: kube-system
update_repo_cache: true
values:
ipam:
mode: kubernetes
wait: true
- name: Configure flannel
when: k8s.network.cni_plugin == 'flannel'
block:
- name: Download flannel manifest
ansible.builtin.get_url:
url: "{{ cni_plugins.flannel.flannel_repo }}"
dest: /tmp/{{ k8s.cluster_name | default('k8s-test', true) }}/kube-flannel.yaml
mode: "0755"
- name: Patch kube-flannel to use host-gw instead of vxlan
ansible.builtin.replace:
path: /tmp/{{ k8s.cluster_name | default('k8s-test', true) }}/kube-flannel.yaml
regexp: "vxlan"
replace: "host-gw"
- name: Apply flannel manifests to the cluster.
kubernetes.core.k8s:
state: present
src: /tmp/{{ k8s.cluster_name | default('k8s-test', true) }}/kube-flannel.yaml
kubeconfig: "{{ workspace_directory.base_path }}/clusters/{{ k8s.cluster_name | default('k8s-test', true) }}/admin.kubeconfig"
wait: true
- name: Wait for core-dns pods to be up and running
kubernetes.core.k8s:
state: present
api_version: v1
kind: Deployment
namespace: kube-system
name: coredns
kubeconfig: "{{ workspace_directory.base_path }}/clusters/{{ k8s.cluster_name | default('k8s-test', true) }}/admin.kubeconfig"
wait: true