blob: d0188e0fea2f61571e407c6fb42e95a73152556e [file] [log] [blame]
Sergiusz Bazanskiaf3be422019-01-17 18:57:19 +01001# Deploy hosted calico with its own etcd.
2
3local kube = import "../../../kube/kube.libsonnet";
4
5local bindServiceAccountClusterRole(sa, cr) = kube.ClusterRoleBinding(cr.metadata.name) {
6 roleRef: {
7 apiGroup: "rbac.authorization.k8s.io",
8 kind: "ClusterRole",
9 name: cr.metadata.name,
10 },
11 subjects: [
12 {
13 kind: "ServiceAccount",
14 name: sa.metadata.name,
15 namespace: sa.metadata.namespace,
16 },
17 ],
18};
19
20{
21 Environment: {
22 local env = self,
23 local cfg = env.cfg,
24 cfg:: {
25 namespace: "kube-system",
Sergiusz Bazanskid81bf722020-05-28 16:38:52 +020026 version: "v3.14.0",
27 imageController: "calico/kube-controllers:" + cfg.version,
28 imageCNI: "calico/cni:" + cfg.version,
29 imageNode: "calico/node:" + cfg.version,
Sergiusz Bazanskiaf3be422019-01-17 18:57:19 +010030 // TODO(q3k): Separate etcd for calico
31 etcd: {
32 endpoints: ["https://bc01n%02d.hswaw.net:2379" % n for n in std.range(1, 3)],
Sergiusz Bazanski73cef112019-04-07 00:06:23 +020033 ca: importstr "../../certs/ca-etcd.crt",
34 cert: importstr "../../certs/etcd-calico.cert",
35 key: importstr "../../secrets/plain/etcd-calico.key",
Sergiusz Bazanskiaf3be422019-01-17 18:57:19 +010036 },
37 },
38
39 cm: kube.ConfigMap("calico-config") {
40 local cm = self,
41 secretPrefix:: "/calico-secrets/",
42
43 metadata+: {
44 namespace: cfg.namespace,
45 },
46
47 data: {
48 etcd_endpoints: std.join(",", cfg.etcd.endpoints),
49
50 etcd_ca: cm.secretPrefix + "etcd-ca",
51 etcd_cert: cm.secretPrefix + "etcd-cert",
52 etcd_key: cm.secretPrefix + "etcd-key",
53
54 calico_backend: "bird",
55 veth_mtu: "1440",
56
Sergiusz Bazanskid81bf722020-05-28 16:38:52 +020057 typha_service_name: "none",
58
Sergiusz Bazanskiaf3be422019-01-17 18:57:19 +010059 cni_network_config: |||
60 {
61 "name": "k8s-pod-network",
Sergiusz Bazanskid81bf722020-05-28 16:38:52 +020062 "cniVersion": "0.3.1",
Sergiusz Bazanskiaf3be422019-01-17 18:57:19 +010063 "plugins": [
64 {
65 "type": "calico",
66 "log_level": "info",
67 "etcd_endpoints": "__ETCD_ENDPOINTS__",
68 "etcd_key_file": "__ETCD_KEY_FILE__",
69 "etcd_cert_file": "__ETCD_CERT_FILE__",
70 "etcd_ca_cert_file": "__ETCD_CA_CERT_FILE__",
Sergiusz Bazanskid81bf722020-05-28 16:38:52 +020071 "datastore_type": "etcdv3",
Sergiusz Bazanskiaf3be422019-01-17 18:57:19 +010072 "mtu": __CNI_MTU__,
73 "ipam": {
74 "type": "calico-ipam"
75 },
76 "policy": {
77 "type": "k8s"
78 },
79 "kubernetes": {
80 "kubeconfig": "__KUBECONFIG_FILEPATH__"
81 }
82 },
83 {
84 "type": "portmap",
85 "snat": true,
86 "capabilities": {"portMappings": true}
Sergiusz Bazanskid81bf722020-05-28 16:38:52 +020087 },
88 {
89 "type": "bandwidth",
90 "capabilities": {"bandwidth": true}
Sergiusz Bazanskiaf3be422019-01-17 18:57:19 +010091 }
92 ]
93 }
94 |||
95 },
96 },
97
98 secrets: kube.Secret("calico-secrets") {
99 metadata+: {
100 namespace: cfg.namespace,
101 },
102
103 data_: {
104 "etcd-ca": cfg.etcd.ca,
105 "etcd-cert": cfg.etcd.cert,
106 "etcd-key": cfg.etcd.key,
107 },
108 },
109
110 saNode: kube.ServiceAccount("calico-node") {
111 metadata+: {
112 namespace: cfg.namespace,
113 },
114 },
115
116 crNode: kube.ClusterRole("calico-node") {
117 rules: [
118 {
119 apiGroups: [""],
120 resources: ["pods", "nodes", "namespaces"],
121 verbs: ["get"],
122 },
123 {
124 apiGroups: [""],
125 resources: ["endpoints", "services"],
Sergiusz Bazanskid81bf722020-05-28 16:38:52 +0200126 verbs: ["watch", "list", "get"],
127 },
128 {
129 apiGroups: [""],
130 resources: ["configmaps"],
131 verbs: ["get"],
Sergiusz Bazanskiaf3be422019-01-17 18:57:19 +0100132 },
133 {
134 apiGroups: [""],
135 resources: ["nodes/status"],
Sergiusz Bazanskid81bf722020-05-28 16:38:52 +0200136 verbs: ["patch", "update"],
137 },
138 {
139 apiGroups: ["networking.k8s.io"],
140 resources: ["networkpolicies"],
141 verbs: ["watch", "list"],
142 },
143 {
144 apiGroups: [""],
145 resources: ["pods", "namespaces", "serviceaccounts"],
146 verbs: ["watch", "list"],
147 },
148 {
149 apiGroups: [""],
150 resources: ["pods/status"],
Sergiusz Bazanskiaf3be422019-01-17 18:57:19 +0100151 verbs: ["patch"],
152 },
Sergiusz Bazanskid81bf722020-05-28 16:38:52 +0200153 {
154 apiGroups: [""],
155 resources: ["nodes"],
156 verbs: ["get", "list", "watch"],
157 },
Sergiusz Bazanskiaf3be422019-01-17 18:57:19 +0100158 ],
159 },
160
161 crbNode: bindServiceAccountClusterRole(env.saNode, env.crNode),
162
163 saController: kube.ServiceAccount("calico-kube-controllers") {
164 metadata+: {
165 namespace: cfg.namespace,
166 },
167 },
168
169 crController: kube.ClusterRole("calico-kube-controllers") {
170 rules: [
171 {
172 apiGroups: [""],
Sergiusz Bazanskid81bf722020-05-28 16:38:52 +0200173 resources: ["nodes"],
174 verbs: ["watch", "list", "get"],
175 },
176 {
177 apiGroups: [""],
178 resources: ["pods"],
179 verbs: ["get"],
Sergiusz Bazanskiaf3be422019-01-17 18:57:19 +0100180 },
181 {
182 apiGroups: ["networking.k8s.io"],
183 resources: ["networkpolicies"],
184 verbs: ["watch", "list"],
185 },
186 ],
187 },
188
189 crbController: bindServiceAccountClusterRole(env.saController, env.crController),
190
191 controller: kube.Deployment("calico-kube-controllers") {
192 metadata+: {
193 namespace: cfg.namespace,
194 annotations+: {
195 "scheduler.alpha.kubernetes.io/critical-pod": "",
196 },
197 },
198 spec+: {
199 replicas: 1,
200 strategy: { type: "Recreate" },
201 template+: {
202 spec+: {
203 hostNetwork: true,
204 tolerations: [
205 { key: "CriticalAddonsOnly", operator: "Exists" },
206 ],
207 serviceAccountName: env.saController.metadata.name,
208 volumes_: {
209 secrets: kube.SecretVolume(env.secrets),
210 },
211 containers_: {
212 "calico-kube-controllers": kube.Container("calico-kube-controllers") {
213 image: cfg.imageController,
214 env_: {
215 ETCD_ENDPOINTS: kube.ConfigMapRef(env.cm, "etcd_endpoints"),
216 ETCD_CA_CERT_FILE: kube.ConfigMapRef(env.cm, "etcd_ca"),
217 ETCD_KEY_FILE: kube.ConfigMapRef(env.cm, "etcd_key"),
218 ETCD_CERT_FILE: kube.ConfigMapRef(env.cm, "etcd_cert"),
219 ENABLED_CONTROLLERS: "policy,namespace,serviceaccount,workloadendpoint,node",
220 },
221 volumeMounts_: {
222 secrets: {
223 mountPath: env.cm.secretPrefix,
224 },
225 },
226 readinessProbe: {
227 exec: {
228 command: [ "/usr/bin/check-status", "-r" ],
229 },
230 },
231 },
232 },
233 },
234 },
235 },
236 },
237
238 nodeDaemon: kube.DaemonSet("calico-node") {
239 metadata+: {
240 namespace: cfg.namespace,
241 },
242 spec+: {
243 template+: {
244 metadata+: {
245 annotations+: {
246 "scheduler.alpha.kubernetes.io/critical-pod": "",
247 },
248 },
249 spec+: {
250 hostNetwork: true,
251 tolerations: [
252 { key: "CriticalAddonsOnly", operator: "Exists" },
Serge Bazanskid493ab62019-10-31 17:07:19 +0100253 { effect: "NoExecute", operator: "Exists" },
254 { effect: "NoSchedule", operator: "Exists" },
Sergiusz Bazanskiaf3be422019-01-17 18:57:19 +0100255 ],
256 serviceAccountName: env.saNode.metadata.name,
257 terminationGracePeriodSeconds: 0,
258 volumes_: {
259 cni_bin: kube.HostPathVolume("/opt/cni/bin"),
260 cni_config: kube.HostPathVolume("/opt/cni/conf"),
261 secrets: kube.SecretVolume(env.secrets),
262 lib_modules: kube.HostPathVolume("/run/current-system/kernel-modules/lib/modules"),
263 xtables_lock: kube.HostPathVolume("/run/xtables.lock"),
264 var_run_calico: kube.HostPathVolume("/var/run/calico"),
265 var_lib_calico: kube.HostPathVolume("/var/lib/calico"),
266 },
267 initContainers_: {
268 installCNI: kube.Container("install-cni") {
269 image: cfg.imageCNI,
270 command: ["/install-cni.sh"],
271 env_: {
272 ETCD_ENDPOINTS: kube.ConfigMapRef(env.cm, "etcd_endpoints"),
273 CNI_CONF_NAME: "10-calico.conflist",
274 CNI_NETWORK_CONFIG: kube.ConfigMapRef(env.cm, "cni_network_config"),
275 CNI_CONF_ETCD_CA_CERT_FILE: kube.ConfigMapRef(env.cm, "etcd_ca"),
276 CNI_CONF_ETCD_KEY_FILE: kube.ConfigMapRef(env.cm, "etcd_key"),
277 CNI_CONF_ETCD_CERT_FILE: kube.ConfigMapRef(env.cm, "etcd_cert"),
278 CNI_MTU: kube.ConfigMapRef(env.cm, "veth_mtu"),
279 CNI_NET_DIR: "/opt/cni/conf",
280 SLEEP: "false",
Sergiusz Bazanskid81bf722020-05-28 16:38:52 +0200281 KUBERNETES_NODE_NAME: { fieldRef: { fieldPath: "spec.nodeName" } },
Sergiusz Bazanskiaf3be422019-01-17 18:57:19 +0100282 },
283 volumeMounts_: {
284 cni_bin: { mountPath: "/host/opt/cni/bin" },
285 cni_config: { mountPath: "/host/etc/cni/net.d" },
286 secrets: { mountPath: env.cm.secretPrefix },
287 },
288 },
289 },
290 containers_: {
291 calicoNode: kube.Container("calico-node") {
292 image: cfg.imageNode,
293 env_: {
Sergiusz Bazanskid81bf722020-05-28 16:38:52 +0200294 DATASTORE_TYPE: "etcdv3",
Sergiusz Bazanskiaf3be422019-01-17 18:57:19 +0100295 ETCD_ENDPOINTS: kube.ConfigMapRef(env.cm, "etcd_endpoints"),
296 ETCD_CA_CERT_FILE: kube.ConfigMapRef(env.cm, "etcd_ca"),
297 ETCD_KEY_FILE: kube.ConfigMapRef(env.cm, "etcd_key"),
298 ETCD_CERT_FILE: kube.ConfigMapRef(env.cm, "etcd_cert"),
299 CALICO_K8S_NODE_REF: kube.FieldRef("spec.nodeName"),
Sergiusz Bazanskid81bf722020-05-28 16:38:52 +0200300 CALICO_NETWORKING_BACKEND: kube.ConfigMapRef(env.cm, "calico_backend"),
Sergiusz Bazanskiaf3be422019-01-17 18:57:19 +0100301 CLUSTER_TYPE: "k8s,bgp",
Sergiusz Bazanskie3af1eb2019-01-18 09:39:57 +0100302 IP: "autodetect",
Serge Bazanskid493ab62019-10-31 17:07:19 +0100303 IP_AUTODETECTION_METHOD: "can-reach=185.236.240.1",
Sergiusz Bazanskiaf3be422019-01-17 18:57:19 +0100304 CALICO_IPV4POOL_IPIP: "Always",
305 FELIX_IPINIPMTU: kube.ConfigMapRef(env.cm, "veth_mtu"),
306 CALICO_IPV4POOL_CIDR: "10.10.24.0/21",
307 CALICO_DISABLE_FILE_LOGGING: "true",
308 FELIX_DEFAULTENDPOINTTOHOSTACTION: "ACCEPT",
309 FELIX_IPV6SUPPORT: "false",
310 FELIX_LOGSEVERITYSCREEN: "info",
311 FELIX_HEALTHENABLED: "true",
Serge Bazanskid493ab62019-10-31 17:07:19 +0100312 FELIX_HEALTHHOST: "127.0.0.1",
Sergiusz Bazanskiaf3be422019-01-17 18:57:19 +0100313 CALICO_ADVERTISE_CLUSTER_IPS: "10.10.12.0/24",
Sergiusz Bazanskid81bf722020-05-28 16:38:52 +0200314 KUBERNETES_NODE_NAME: { fieldRef: { fieldPath: "spec.nodeName" } },
Sergiusz Bazanskiaf3be422019-01-17 18:57:19 +0100315 },
316 securityContext: {
317 privileged: true,
318 },
319 resources: {
320 requests: { cpu: "250m" },
321 },
322 livenessProbe: {
Sergiusz Bazanskid81bf722020-05-28 16:38:52 +0200323 exec: {
324 command: ["/bin/calico-node", "-bird-live", "-felix-live"],
Sergiusz Bazanskiaf3be422019-01-17 18:57:19 +0100325 },
326 periodSeconds: 10,
327 initialDelaySeconds: 10,
328 failureThreshold: 6,
329 },
330 readinessProbe: {
331 exec: {
332 command: ["/bin/calico-node", "-bird-ready", "-felix-ready"],
333 },
334 periodSeconds: 10,
335 },
336 volumeMounts_: {
337 lib_modules: { mountPath: "/lib/modules" },
338 xtables_lock: { mountPath: "/run/xtables.lock" },
339 var_run_calico: { mountPath: "/var/run/calico" },
340 var_lib_calico: { mountPath: "/var/lib/calico" },
341 secrets: { mountPath: env.cm.secretPrefix },
342 },
343 },
344 },
345 },
346 },
347 },
348 },
349 },
350}