uCPE Blueprint
[eliot.git] / blueprints / uCPE / cni / calico / calico.yaml
1 # Calico Version v3.3.4
2 # https://docs.projectcalico.org/v3.3/releases#v3.3.4
3 # This manifest includes the following component versions:
4 #   calico/node:v3.3.4
5 #   calico/cni:v3.3.4
6 #
7
8 # This ConfigMap is used to configure a self-hosted Calico installation.
9 ---
10 kind: ConfigMap
11 apiVersion: v1
12 metadata:
13   name: calico-config
14   namespace: kube-system
15 data:
16   # To enable Typha, set this to "calico-typha" *and*
17   # set a non-zero value for Typha replicas
18   # below.  We recommend using Typha if you have more than 50 nodes.
19   # Above 100 nodes it is essential.
20   typha_service_name: "none"
21   # Configure the Calico backend to use.
22   calico_backend: "bird"
23
24   # Configure the MTU to use
25   veth_mtu: "1440"
26
27   # The CNI network configuration to install on each node.  The special
28   # values in this config will be automatically populated.
29   cni_network_config: |-
30     {
31       "name": "k8s-pod-network",
32       "cniVersion": "0.3.0",
33       "plugins": [
34         {
35           "type": "calico",
36           "log_level": "info",
37           "datastore_type": "kubernetes",
38           "nodename": "__KUBERNETES_NODE_NAME__",
39           "mtu": __CNI_MTU__,
40           "ipam": {
41             "type": "host-local",
42             "subnet": "usePodCidr"
43           },
44           "policy": {
45               "type": "k8s"
46           },
47           "kubernetes": {
48               "kubeconfig": "__KUBECONFIG_FILEPATH__"
49           }
50         },
51         {
52           "type": "portmap",
53           "snat": true,
54           "capabilities": {"portMappings": true}
55         }
56       ]
57     }
58
59 ---
60
61
62 # This manifest creates a Service,
63 # which will be backed by Calico's Typha daemon.
64 # Typha sits in between Felix and the API server,
65 # reducing Calico's load on the API server.
66
67 apiVersion: v1
68 kind: Service
69 metadata:
70   name: calico-typha
71   namespace: kube-system
72   labels:
73     k8s-app: calico-typha
74 spec:
75   ports:
76     - port: 5473
77       protocol: TCP
78       targetPort: calico-typha
79       name: calico-typha
80   selector:
81     k8s-app: calico-typha
82
83 ---
84
85 # This manifest creates a Deployment of Typha to back the above service.
86
87 apiVersion: apps/v1beta1
88 kind: Deployment
89 metadata:
90   name: calico-typha
91   namespace: kube-system
92   labels:
93     k8s-app: calico-typha
94 spec:
95   # Number of Typha replicas.
96   # To enable Typha, set this to a non-zero value *and* set the
97   # typha_service_name variable in the calico-config ConfigMap above.
98   #
99   # We recommend using Typha if you have more than 50 nodes.
100   # Above 100 nodes it is essential
101   # (when using the Kubernetes datastore).
102   # Use one replica for every 100-200 nodes.  In production,
103   # we recommend running at least 3 replicas to reduce the
104   # impact of rolling upgrade.
105   replicas: 0
106   revisionHistoryLimit: 2
107   template:
108     metadata:
109       labels:
110         k8s-app: calico-typha
111       annotations:
112         # This, along with the CriticalAddonsOnly toleration below,
113         # marks the pod as a critical
114         # add-on, ensuring it gets priority scheduling
115         # and that its resources are reserved
116         # if it ever gets evicted.
117         scheduler.alpha.kubernetes.io/critical-pod: ''
118         cluster-autoscaler.kubernetes.io/safe-to-evict: 'true'
119     spec:
120       nodeSelector:
121         beta.kubernetes.io/os: linux
122       hostNetwork: true
123       tolerations:
124         # Mark the pod as a critical add-on for rescheduling.
125         - key: CriticalAddonsOnly
126           operator: Exists
127       # Since Calico can't network a pod until Typha is up,
128       # we need to run Typha itself as a host-networked pod.
129       serviceAccountName: calico-node
130       containers:
131         - image: calico/typha:v3.3.4
132           name: calico-typha
133           ports:
134             - containerPort: 5473
135               name: calico-typha
136               protocol: TCP
137           env:
138             # Enable "info" logging by default.
139             # Can be set to "debug" to increase verbosity.
140             - name: TYPHA_LOGSEVERITYSCREEN
141               value: "info"
142             # Disable logging to file and syslog
143             # since those don't make sense in K8s.
144             - name: TYPHA_LOGFILEPATH
145               value: "none"
146             - name: TYPHA_LOGSEVERITYSYS
147               value: "none"
148             # Monitor the Kubernetes API to find the number of running instances
149             # and rebalance connections.
150             - name: TYPHA_CONNECTIONREBALANCINGMODE
151               value: "kubernetes"
152             - name: TYPHA_DATASTORETYPE
153               value: "kubernetes"
154             - name: TYPHA_HEALTHENABLED
155               value: "true"
156               # Uncomment these lines to enable prometheus metrics.
157               # Since Typha is host-networked,
158               # this opens a port on the host, which may need to be secured.
159               # - name: TYPHA_PROMETHEUSMETRICSENABLED
160               #  value: "true"
161               # - name: TYPHA_PROMETHEUSMETRICSPORT
162               #  value: "9093"
163           livenessProbe:
164             exec:
165               command:
166                 - calico-typha
167                 - check
168                 - liveness
169             periodSeconds: 30
170             initialDelaySeconds: 30
171           readinessProbe:
172             exec:
173               command:
174                 - calico-typha
175                 - check
176                 - readiness
177             periodSeconds: 10
178 ---
179
180 # This manifest creates a Pod Disruption Budget
181 # for Typha to allow K8s Cluster Autoscaler to evict
182
183 apiVersion: policy/v1beta1
184 kind: PodDisruptionBudget
185 metadata:
186   name: calico-typha
187   namespace: kube-system
188   labels:
189     k8s-app: calico-typha
190 spec:
191   maxUnavailable: 1
192   selector:
193     matchLabels:
194       k8s-app: calico-typha
195
196 ---
197
198 # This manifest installs the calico/node container, as well
199 # as the Calico CNI plugins and network config on
200 # each master and worker node in a Kubernetes cluster.
201 kind: DaemonSet
202 apiVersion: extensions/v1beta1
203 metadata:
204   name: calico-node
205   namespace: kube-system
206   labels:
207     k8s-app: calico-node
208 spec:
209   selector:
210     matchLabels:
211       k8s-app: calico-node
212   updateStrategy:
213     type: RollingUpdate
214     rollingUpdate:
215       maxUnavailable: 1
216   template:
217     metadata:
218       labels:
219         k8s-app: calico-node
220       annotations:
221         # This, along with the CriticalAddonsOnly toleration below,
222         # marks the pod as a critical add-on, ensuring it gets
223         # priority scheduling and that its resources are reserved
224         # if it ever gets evicted.
225         scheduler.alpha.kubernetes.io/critical-pod: ''
226     spec:
227       nodeSelector:
228         beta.kubernetes.io/os: linux
229       hostNetwork: true
230       tolerations:
231         # Make sure calico-node gets scheduled on all nodes.
232         - effect: NoSchedule
233           operator: Exists
234         # Mark the pod as a critical add-on for rescheduling.
235         - key: CriticalAddonsOnly
236           operator: Exists
237         - effect: NoExecute
238           operator: Exists
239       serviceAccountName: calico-node
240       # Minimize downtime during a rolling upgrade or deletion;
241       # tell Kubernetes to do a "force deletion"
242       # https://kubernetes.io/docs/concepts
243       # /workloads/pods/pod/#termination-of-pods.
244       terminationGracePeriodSeconds: 0
245       containers:
246         # Runs calico/node container on each Kubernetes node.  This
247         # container programs network policy and routes on each
248         # host.
249         - name: calico-node
250           image: calico/node:v3.3.4
251           env:
252             # Use Kubernetes API as the backing datastore.
253             - name: DATASTORE_TYPE
254               value: "kubernetes"
255             # Typha support: controlled by the ConfigMap.
256             - name: FELIX_TYPHAK8SSERVICENAME
257               valueFrom:
258                 configMapKeyRef:
259                   name: calico-config
260                   key: typha_service_name
261             # Wait for the datastore.
262             - name: WAIT_FOR_DATASTORE
263               value: "true"
264             # Set based on the k8s node name.
265             - name: NODENAME
266               valueFrom:
267                 fieldRef:
268                   fieldPath: spec.nodeName
269             # Choose the backend to use.
270             - name: CALICO_NETWORKING_BACKEND
271               valueFrom:
272                 configMapKeyRef:
273                   name: calico-config
274                   key: calico_backend
275             # Cluster type to identify the deployment type
276             - name: CLUSTER_TYPE
277               value: "k8s,bgp"
278             # Auto-detect the BGP IP address.
279             - name: IP
280               value: "autodetect"
281             # Enable IPIP
282             - name: CALICO_IPV4POOL_IPIP
283               value: "Always"
284             # Set MTU for tunnel device used if ipip is enabled
285             - name: FELIX_IPINIPMTU
286               valueFrom:
287                 configMapKeyRef:
288                   name: calico-config
289                   key: veth_mtu
290             # The default IPv4 pool to create on startup if none exists.
291             # Pod IPs will be   chosen from this range.
292             # Changing this value after installation will have
293             # no effect. This should fall within `--cluster-cidr`.
294             - name: CALICO_IPV4POOL_CIDR
295               value: "192.168.0.0/16"
296             # Disable file logging so `kubectl logs` works.
297             - name: CALICO_DISABLE_FILE_LOGGING
298               value: "true"
299             # Set Felix endpoint to host default action to ACCEPT.
300             - name: FELIX_DEFAULTENDPOINTTOHOSTACTION
301               value: "ACCEPT"
302             # Disable IPv6 on Kubernetes.
303             - name: FELIX_IPV6SUPPORT
304               value: "false"
305             # Set Felix logging to "info"
306             - name: FELIX_LOGSEVERITYSCREEN
307               value: "info"
308             - name: FELIX_HEALTHENABLED
309               value: "true"
310           securityContext:
311             privileged: true
312           resources:
313             requests:
314               cpu: 250m
315           livenessProbe:
316             httpGet:
317               path: /liveness
318               port: 9099
319               host: localhost
320             periodSeconds: 10
321             initialDelaySeconds: 10
322             failureThreshold: 6
323           readinessProbe:
324             exec:
325               command:
326                 - /bin/calico-node
327                 - -bird-ready
328                 - -felix-ready
329             periodSeconds: 10
330           volumeMounts:
331             - mountPath: /lib/modules
332               name: lib-modules
333               readOnly: true
334             - mountPath: /run/xtables.lock
335               name: xtables-lock
336               readOnly: false
337             - mountPath: /var/run/calico
338               name: var-run-calico
339               readOnly: false
340             - mountPath: /var/lib/calico
341               name: var-lib-calico
342               readOnly: false
343         # This container installs the Calico CNI binaries
344         # and CNI network config file on each node.
345         - name: install-cni
346           image: calico/cni:v3.3.4
347           command: ["/install-cni.sh"]
348           env:
349             # Name of the CNI config file to create.
350             - name: CNI_CONF_NAME
351               value: "10-calico.conflist"
352             # Set the hostname based on the k8s node name.
353             - name: KUBERNETES_NODE_NAME
354               valueFrom:
355                 fieldRef:
356                   fieldPath: spec.nodeName
357             # The CNI network config to install on each node.
358             - name: CNI_NETWORK_CONFIG
359               valueFrom:
360                 configMapKeyRef:
361                   name: calico-config
362                   key: cni_network_config
363             # CNI MTU Config variable
364             - name: CNI_MTU
365               valueFrom:
366                 configMapKeyRef:
367                   name: calico-config
368                   key: veth_mtu
369           volumeMounts:
370             - mountPath: /host/opt/cni/bin
371               name: cni-bin-dir
372             - mountPath: /host/etc/cni/net.d
373               name: cni-net-dir
374       volumes:
375         # Used by calico/node.
376         - name: lib-modules
377           hostPath:
378             path: /lib/modules
379         - name: var-run-calico
380           hostPath:
381             path: /var/run/calico
382         - name: var-lib-calico
383           hostPath:
384             path: /var/lib/calico
385         - name: xtables-lock
386           hostPath:
387             path: /run/xtables.lock
388             type: FileOrCreate
389         # Used to install CNI.
390         - name: cni-bin-dir
391           hostPath:
392             path: /opt/cni/bin
393         - name: cni-net-dir
394           hostPath:
395             path: /etc/cni/net.d
396 ---
397
398 apiVersion: v1
399 kind: ServiceAccount
400 metadata:
401   name: calico-node
402   namespace: kube-system
403
404 ---
405
406 # Create all the CustomResourceDefinitions needed for
407 # Calico policy and networking mode.
408
409 apiVersion: apiextensions.k8s.io/v1beta1
410 kind: CustomResourceDefinition
411 metadata:
412   name: felixconfigurations.crd.projectcalico.org
413 spec:
414   scope: Cluster
415   group: crd.projectcalico.org
416   version: v1
417   names:
418     kind: FelixConfiguration
419     plural: felixconfigurations
420     singular: felixconfiguration
421 ---
422
423 apiVersion: apiextensions.k8s.io/v1beta1
424 kind: CustomResourceDefinition
425 metadata:
426   name: bgppeers.crd.projectcalico.org
427 spec:
428   scope: Cluster
429   group: crd.projectcalico.org
430   version: v1
431   names:
432     kind: BGPPeer
433     plural: bgppeers
434     singular: bgppeer
435
436 ---
437
438 apiVersion: apiextensions.k8s.io/v1beta1
439 kind: CustomResourceDefinition
440 metadata:
441   name: bgpconfigurations.crd.projectcalico.org
442 spec:
443   scope: Cluster
444   group: crd.projectcalico.org
445   version: v1
446   names:
447     kind: BGPConfiguration
448     plural: bgpconfigurations
449     singular: bgpconfiguration
450
451 ---
452
453 apiVersion: apiextensions.k8s.io/v1beta1
454 kind: CustomResourceDefinition
455 metadata:
456   name: ippools.crd.projectcalico.org
457 spec:
458   scope: Cluster
459   group: crd.projectcalico.org
460   version: v1
461   names:
462     kind: IPPool
463     plural: ippools
464     singular: ippool
465
466 ---
467
468 apiVersion: apiextensions.k8s.io/v1beta1
469 kind: CustomResourceDefinition
470 metadata:
471   name: hostendpoints.crd.projectcalico.org
472 spec:
473   scope: Cluster
474   group: crd.projectcalico.org
475   version: v1
476   names:
477     kind: HostEndpoint
478     plural: hostendpoints
479     singular: hostendpoint
480
481 ---
482
483 apiVersion: apiextensions.k8s.io/v1beta1
484 kind: CustomResourceDefinition
485 metadata:
486   name: clusterinformations.crd.projectcalico.org
487 spec:
488   scope: Cluster
489   group: crd.projectcalico.org
490   version: v1
491   names:
492     kind: ClusterInformation
493     plural: clusterinformations
494     singular: clusterinformation
495
496 ---
497
498 apiVersion: apiextensions.k8s.io/v1beta1
499 kind: CustomResourceDefinition
500 metadata:
501   name: globalnetworkpolicies.crd.projectcalico.org
502 spec:
503   scope: Cluster
504   group: crd.projectcalico.org
505   version: v1
506   names:
507     kind: GlobalNetworkPolicy
508     plural: globalnetworkpolicies
509     singular: globalnetworkpolicy
510
511 ---
512
513 apiVersion: apiextensions.k8s.io/v1beta1
514 kind: CustomResourceDefinition
515 metadata:
516   name: globalnetworksets.crd.projectcalico.org
517 spec:
518   scope: Cluster
519   group: crd.projectcalico.org
520   version: v1
521   names:
522     kind: GlobalNetworkSet
523     plural: globalnetworksets
524     singular: globalnetworkset
525
526 ---
527
528 apiVersion: apiextensions.k8s.io/v1beta1
529 kind: CustomResourceDefinition
530 metadata:
531   name: networkpolicies.crd.projectcalico.org
532 spec:
533   scope: Namespaced
534   group: crd.projectcalico.org
535   version: v1
536   names:
537     kind: NetworkPolicy
538     plural: networkpolicies
539     singular: networkpolicy