blob: b5c83a7d7c0e74f519f504366a6926894a025e2d [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 Bazanskie55493f2020-05-30 17:57:05 +0200173 resources: ["nodes", "pods", "namespaces", "serviceaccounts"],
Sergiusz Bazanskid81bf722020-05-28 16:38:52 +0200174 verbs: ["watch", "list", "get"],
175 },
176 {
Sergiusz Bazanskiaf3be422019-01-17 18:57:19 +0100177 apiGroups: ["networking.k8s.io"],
178 resources: ["networkpolicies"],
179 verbs: ["watch", "list"],
180 },
181 ],
182 },
183
184 crbController: bindServiceAccountClusterRole(env.saController, env.crController),
185
186 controller: kube.Deployment("calico-kube-controllers") {
187 metadata+: {
188 namespace: cfg.namespace,
189 annotations+: {
190 "scheduler.alpha.kubernetes.io/critical-pod": "",
191 },
192 },
193 spec+: {
194 replicas: 1,
195 strategy: { type: "Recreate" },
196 template+: {
197 spec+: {
198 hostNetwork: true,
199 tolerations: [
200 { key: "CriticalAddonsOnly", operator: "Exists" },
201 ],
202 serviceAccountName: env.saController.metadata.name,
203 volumes_: {
204 secrets: kube.SecretVolume(env.secrets),
205 },
206 containers_: {
207 "calico-kube-controllers": kube.Container("calico-kube-controllers") {
208 image: cfg.imageController,
209 env_: {
210 ETCD_ENDPOINTS: kube.ConfigMapRef(env.cm, "etcd_endpoints"),
211 ETCD_CA_CERT_FILE: kube.ConfigMapRef(env.cm, "etcd_ca"),
212 ETCD_KEY_FILE: kube.ConfigMapRef(env.cm, "etcd_key"),
213 ETCD_CERT_FILE: kube.ConfigMapRef(env.cm, "etcd_cert"),
214 ENABLED_CONTROLLERS: "policy,namespace,serviceaccount,workloadendpoint,node",
215 },
216 volumeMounts_: {
217 secrets: {
218 mountPath: env.cm.secretPrefix,
219 },
220 },
221 readinessProbe: {
222 exec: {
223 command: [ "/usr/bin/check-status", "-r" ],
224 },
225 },
226 },
227 },
228 },
229 },
230 },
231 },
232
233 nodeDaemon: kube.DaemonSet("calico-node") {
234 metadata+: {
235 namespace: cfg.namespace,
236 },
237 spec+: {
238 template+: {
239 metadata+: {
240 annotations+: {
241 "scheduler.alpha.kubernetes.io/critical-pod": "",
242 },
243 },
244 spec+: {
245 hostNetwork: true,
246 tolerations: [
247 { key: "CriticalAddonsOnly", operator: "Exists" },
Serge Bazanskid493ab62019-10-31 17:07:19 +0100248 { effect: "NoExecute", operator: "Exists" },
249 { effect: "NoSchedule", operator: "Exists" },
Sergiusz Bazanskiaf3be422019-01-17 18:57:19 +0100250 ],
251 serviceAccountName: env.saNode.metadata.name,
252 terminationGracePeriodSeconds: 0,
253 volumes_: {
254 cni_bin: kube.HostPathVolume("/opt/cni/bin"),
255 cni_config: kube.HostPathVolume("/opt/cni/conf"),
256 secrets: kube.SecretVolume(env.secrets),
257 lib_modules: kube.HostPathVolume("/run/current-system/kernel-modules/lib/modules"),
258 xtables_lock: kube.HostPathVolume("/run/xtables.lock"),
259 var_run_calico: kube.HostPathVolume("/var/run/calico"),
260 var_lib_calico: kube.HostPathVolume("/var/lib/calico"),
261 },
262 initContainers_: {
263 installCNI: kube.Container("install-cni") {
264 image: cfg.imageCNI,
265 command: ["/install-cni.sh"],
266 env_: {
267 ETCD_ENDPOINTS: kube.ConfigMapRef(env.cm, "etcd_endpoints"),
268 CNI_CONF_NAME: "10-calico.conflist",
269 CNI_NETWORK_CONFIG: kube.ConfigMapRef(env.cm, "cni_network_config"),
270 CNI_CONF_ETCD_CA_CERT_FILE: kube.ConfigMapRef(env.cm, "etcd_ca"),
271 CNI_CONF_ETCD_KEY_FILE: kube.ConfigMapRef(env.cm, "etcd_key"),
272 CNI_CONF_ETCD_CERT_FILE: kube.ConfigMapRef(env.cm, "etcd_cert"),
273 CNI_MTU: kube.ConfigMapRef(env.cm, "veth_mtu"),
274 CNI_NET_DIR: "/opt/cni/conf",
275 SLEEP: "false",
Sergiusz Bazanskid81bf722020-05-28 16:38:52 +0200276 KUBERNETES_NODE_NAME: { fieldRef: { fieldPath: "spec.nodeName" } },
Sergiusz Bazanskiaf3be422019-01-17 18:57:19 +0100277 },
278 volumeMounts_: {
279 cni_bin: { mountPath: "/host/opt/cni/bin" },
280 cni_config: { mountPath: "/host/etc/cni/net.d" },
281 secrets: { mountPath: env.cm.secretPrefix },
282 },
283 },
284 },
285 containers_: {
286 calicoNode: kube.Container("calico-node") {
287 image: cfg.imageNode,
288 env_: {
Sergiusz Bazanskid81bf722020-05-28 16:38:52 +0200289 DATASTORE_TYPE: "etcdv3",
Sergiusz Bazanskiaf3be422019-01-17 18:57:19 +0100290 ETCD_ENDPOINTS: kube.ConfigMapRef(env.cm, "etcd_endpoints"),
291 ETCD_CA_CERT_FILE: kube.ConfigMapRef(env.cm, "etcd_ca"),
292 ETCD_KEY_FILE: kube.ConfigMapRef(env.cm, "etcd_key"),
293 ETCD_CERT_FILE: kube.ConfigMapRef(env.cm, "etcd_cert"),
294 CALICO_K8S_NODE_REF: kube.FieldRef("spec.nodeName"),
Sergiusz Bazanskid81bf722020-05-28 16:38:52 +0200295 CALICO_NETWORKING_BACKEND: kube.ConfigMapRef(env.cm, "calico_backend"),
Sergiusz Bazanskiaf3be422019-01-17 18:57:19 +0100296 CLUSTER_TYPE: "k8s,bgp",
Sergiusz Bazanskie3af1eb2019-01-18 09:39:57 +0100297 IP: "autodetect",
Serge Bazanskid493ab62019-10-31 17:07:19 +0100298 IP_AUTODETECTION_METHOD: "can-reach=185.236.240.1",
Sergiusz Bazanskiaf3be422019-01-17 18:57:19 +0100299 CALICO_IPV4POOL_IPIP: "Always",
300 FELIX_IPINIPMTU: kube.ConfigMapRef(env.cm, "veth_mtu"),
301 CALICO_IPV4POOL_CIDR: "10.10.24.0/21",
302 CALICO_DISABLE_FILE_LOGGING: "true",
303 FELIX_DEFAULTENDPOINTTOHOSTACTION: "ACCEPT",
304 FELIX_IPV6SUPPORT: "false",
305 FELIX_LOGSEVERITYSCREEN: "info",
306 FELIX_HEALTHENABLED: "true",
Serge Bazanskid493ab62019-10-31 17:07:19 +0100307 FELIX_HEALTHHOST: "127.0.0.1",
Sergiusz Bazanskiaf3be422019-01-17 18:57:19 +0100308 CALICO_ADVERTISE_CLUSTER_IPS: "10.10.12.0/24",
Sergiusz Bazanskid81bf722020-05-28 16:38:52 +0200309 KUBERNETES_NODE_NAME: { fieldRef: { fieldPath: "spec.nodeName" } },
Sergiusz Bazanskiaf3be422019-01-17 18:57:19 +0100310 },
311 securityContext: {
312 privileged: true,
313 },
314 resources: {
315 requests: { cpu: "250m" },
316 },
317 livenessProbe: {
Sergiusz Bazanskid81bf722020-05-28 16:38:52 +0200318 exec: {
319 command: ["/bin/calico-node", "-bird-live", "-felix-live"],
Sergiusz Bazanskiaf3be422019-01-17 18:57:19 +0100320 },
321 periodSeconds: 10,
322 initialDelaySeconds: 10,
323 failureThreshold: 6,
324 },
325 readinessProbe: {
326 exec: {
327 command: ["/bin/calico-node", "-bird-ready", "-felix-ready"],
328 },
329 periodSeconds: 10,
330 },
331 volumeMounts_: {
332 lib_modules: { mountPath: "/lib/modules" },
333 xtables_lock: { mountPath: "/run/xtables.lock" },
334 var_run_calico: { mountPath: "/var/run/calico" },
335 var_lib_calico: { mountPath: "/var/lib/calico" },
336 secrets: { mountPath: env.cm.secretPrefix },
337 },
338 },
339 },
340 },
341 },
342 },
343 },
344 },
345}