-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkubernetes.yml
204 lines (203 loc) · 6.65 KB
/
kubernetes.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# Provision kubernetes on bare metal hosts
---
- name: Prepare requirements and install Kubernetes on bare-metal hosts
hosts: servers
become: true
gather_facts: true
vars:
# These values are explicitly defined here so that changes to CIDRs, etc,
# are propagated to the roles. In most cases they match the defaults for
# each role.
api_bind_port: 6443
api_external_hostname: "control.{{ lab_domain | default('lab.acceleratedgcp.com') }}"
api_external_port: 6443
bgp_peer: 172.16.96.1
bgp_peer_asn: 64512
bgp_asn: 64513
certificate_dir: ./certs/kubernetes/
cluster_name: lab
link_device: bond0
dataplane_device: "{{ link_device }}.100"
dns_domain: cluster.local
ipv4_native_routing_cidr: 172.16.96.0/20
lb_cidrs:
- 172.16.105.0/24
- 2001:470:49a5:84::/112
pod_cidrs:
- 172.16.100.0/22
- 2001:470:49a5:82::/96
overrides:
96:
nameservers:
addresses:
- 172.16.96.1
- '2001:470:49a5:80::1'
routing-policy:
- from: 172.16.96.0/20
priority: 1000
table: 96
- from: '2001:470:49a5:80::/57'
priority: 1000
table: 96
routes:
- to: 0.0.0.0/0
via: 172.16.96.1
table: 96
# metric: 50
- to: ::/0
via: '2001:470:49a5:80::1'
table: 96
# metric: 50
service_cidrs:
- 172.16.104.0/24
- 2001:470:49a5:83::/112
skip_phases:
init:
- addon/kube-proxy
join:
- control-plane-prepare/download-certs
upstream_dns:
- 172.16.96.1
- '2001:470:49a5:80::1'
tasks:
- name: Setup networking for VLAN 96
ansible.builtin.include_role:
name: networking
vars:
# yamllint disable-line rule:line-length
networking_vlans: "{{ hostvars[inventory_hostname]['vlans'] | combine(overrides | default({}), recursive=true) }}"
- name: Prepare hosts for kubernetes
ansible.builtin.include_role:
name: pre_kube
- name: Flush pending handlers
ansible.builtin.meta: flush_handlers
- name: Reset connections
ansible.builtin.meta: reset_connection
- name: Install CRI-O
ansible.builtin.include_role:
name: crio
- name: Install Kubernetes with Kubeadm
ansible.builtin.include_role:
name: kubeadm
vars:
kubeadm_node_addresses: "{{ vlans[96]['addresses'] }}"
- name: Flush pending handlers
ansible.builtin.meta: flush_handlers
- name: Remove scheduling taints from masters that are also workers
kubernetes.core.k8s_taint:
ca_cert: "{{ certificate_dir }}/ca.chain.pem"
state: absent
name: "{{ k8s.node_name }}"
taints:
- effect: NoSchedule
key: node-role.kubernetes.io/control-plane
- effect: NoSchedule
key: node-role.kubernetes.io/master
when: (k8s.master | default(False)) and (k8s.worker | default(True))
delegate_to: 127.0.0.1
become: false
- name: Set upstream DNS for CoreDNS
kubernetes.core.k8s:
ca_cert: "{{ certificate_dir }}/ca.chain.pem"
state: patched
kind: ConfigMap
name: coredns
namespace: kube-system
definition:
data:
# yamllint disable rule:line-length
Corefile: |
.:53 {
errors
health {
lameduck 5s
}
ready
kubernetes {{ dns_domain }} in-addr.arpa ip6.arpa {
pods insecure
fallthrough in-addr.arpa ip6.arpa
ttl 30
}
prometheus :9153
forward . {{ upstream_dns | unique | ansible.utils.ipwrap | map('regex_replace', '$', ':53') | join(' ') }} {
max_concurrent 1000
}
cache 30
loop
reload
loadbalance
}
# yamllint enable rule:line-length
delegate_to: 127.0.0.1
become: false
run_once: true
- name: Delete running CoreDNS pods
kubernetes.core.k8s:
ca_cert: "{{ certificate_dir }}/ca.chain.pem"
state: absent
kind: Pod
namespace: kube-system
label_selectors:
- k8s-app=kube-dns
delete_options:
gracePeriodSeconds: 1
delegate_to: 127.0.0.1
become: false
run_once: true
- name: Wait for CoreDNS to be ready
kubernetes.core.k8s_info:
ca_cert: "{{ certificate_dir }}/ca.chain.pem"
kind: Deployment
name: coredns
namespace: kube-system
register: coredns_ready
until: coredns_ready.resources | json_query('[0].status | numberReady == desiredNumberScheduled')
delay: 10
retries: 6
delegate_to: 127.0.0.1
become: false
run_once: true
- name: Allow unauthenticated access to OIDC discovery URL for Vault integration
kubernetes.core.k8s:
ca_cert: "{{ certificate_dir }}/ca.chain.pem"
state: present
force: true
name: external-secrets-oidc-reviewer
api_version: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
definition:
roleRef:
kind: ClusterRole
name: system:service-account-issuer-discovery
subjects:
- kind: Group
name: system:unauthenticated
delegate_to: 127.0.0.1
become: false
run_once: true
- name: Allow OIDC integration with kubernetes tokens by configuring the *existing* auth mount via OIDC discovery
community.hashi_vault.vault_write:
path: auth/k8s/config
data:
oidc_discovery_url: "https://{{ api_external_hostname }}:{{ api_external_port }}"
# yamllint disable-line rule:line-length
oidc_discovery_ca_pem: "{{ lookup('ansible.builtin.file', certificate_dir + './ca.chain.pem') | ansible.builtin.regex_replace('\r?\n+','\\n') }}"
delegate_to: 127.0.0.1
become: false
run_once: true
- name: Install Cilium
ansible.builtin.include_role:
name: cilium
# https://docs.cilium.io/en/stable/network/kubernetes/configuration/#crio
- name: Restart CRI-O to recognise Cilium
ansible.builtin.systemd:
name: kubelet
enabled: true
state: restarted
daemon_reload: false
- name: Install external-secrets
ansible.builtin.include_role:
name: external_secrets
- name: Install Longhorn
ansible.builtin.include_role:
name: longhorn