Merge "Eliminate warning about apt stable CLI interface"
[icn.git] / deploy / cluster / templates / kubeadmcontrolplane.yaml
1 ---
2 apiVersion: controlplane.cluster.x-k8s.io/v1alpha4
3 kind: KubeadmControlPlane
4 metadata:
5   name: {{ .Values.clusterName }}
6 spec:
7   kubeadmConfigSpec:
8     clusterConfiguration:
9       apiServer:
10         extraArgs:
11           enable-admission-plugins: NodeRestriction,PodSecurityPolicy
12     initConfiguration:
13       nodeRegistration:
14         kubeletExtraArgs:
15           node-labels: metal3.io/uuid={{ "{{" }} ds.meta_data.uuid {{ "}}" }}
16           cpu-manager-policy: static
17           topology-manager-policy: best-effort
18           kube-reserved: cpu=200m,memory=512Mi
19         name: '{{ "{{" }} ds.meta_data.name {{ "}}" }}'
20     joinConfiguration:
21       controlPlane: {}
22       nodeRegistration:
23         kubeletExtraArgs:
24           node-labels: metal3.io/uuid={{ "{{" }} ds.meta_data.uuid {{ "}}" }}
25           cpu-manager-policy: static
26           topology-manager-policy: best-effort
27           kube-reserved: cpu=200m,memory=512Mi
28         name: '{{ "{{" }} ds.meta_data.name {{ "}}" }}'
29     preKubeadmCommands:
30 {{- if .Values.networks }}
31     # Without touching up /etc/hosts, kubeadm may pick the wrong
32     # (i.e. provisioning network) address for the node IP
33     - sed -i "1i $(ip -4 addr show dev {{ .Values.networks.baremetal.interface }} | grep -oP '(?<=inet\s)\d+(\.\d+){3}' | head -1) $(hostname)" /etc/hosts
34 {{- end }}
35     - curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
36     - add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
37     - curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
38     - add-apt-repository "deb https://apt.kubernetes.io/ kubernetes-xenial main"
39     - apt-get update -y
40     - apt-get install -y ca-certificates
41 {{- if .Values.keepalived }}
42     - apt-get install -y keepalived
43     - systemctl enable --now keepalived
44 {{- end }}
45     - /usr/local/bin/install-container-runtime.sh
46     - apt-get install -y kubelet={{ .Values.kubeVersion }} kubeadm={{ .Values.kubeVersion }} kubectl={{ .Values.kubeVersion }}
47     - systemctl enable --now kubelet
48     postKubeadmCommands:
49     - mkdir -p /home/ubuntu/.kube
50     - cp /etc/kubernetes/admin.conf /home/ubuntu/.kube/config
51     - chown ubuntu:ubuntu /home/ubuntu/.kube/config
52     - mkdir -p /root/.kube
53     - cp /etc/kubernetes/admin.conf /root/.kube/config
54     - /usr/local/bin/harden_os.sh
55     # Normally any bootstrap resources needed would be applied with a
56     # ClusterResourceSet.  However instead of apply, replace must be
57     # used to harden K8s.
58     - /usr/local/bin/harden_k8s.sh
59 {{- if eq (int .Values.numWorkerMachines) 0 }}
60     # Allow scheduling Pods on the control plane when there are no
61     # workers.
62     - kubectl --kubeconfig=/etc/kubernetes/admin.conf taint nodes --all node-role.kubernetes.io/master-
63 {{- end }}
64     # This must be done after kubeadm as the cabpk provider relies on
65     # files in /var/run, which won't persist after a reboot
66     - /usr/local/bin/set_kernel_cmdline.sh
67     files:
68 {{ include "cluster.keepalived" .Values | indent 4 }}
69 {{ include "cluster.containerRuntime" .Values | indent 4 }}
70     - path: /etc/systemd/system/containerd.service.d/override.conf
71       content: |
72 {{ $.Files.Get "resources/override.conf" | indent 8 }}
73     - path: /usr/local/bin/harden_os.sh
74       permissions: '0777'
75       content: |
76 {{ $.Files.Get "resources/harden_os.sh" | indent 8 }}
77     - path: /usr/local/bin/harden_k8s.sh
78       permissions: '0777'
79       content: |
80 {{ $.Files.Get "resources/harden_k8s.sh" | indent 8 }}
81     - path: /usr/local/bin/set_kernel_cmdline.sh
82       permissions: '0777'
83       content: |
84 {{ $.Files.Get "resources/set_kernel_cmdline.sh" | indent 8 }}
85     users:
86     - name: {{ .Values.userData.name }}
87       shell: /bin/bash
88       lockPassword: False # Necessary to allow password login
89       passwd: {{ .Values.userData.hashedPassword }}
90       sshAuthorizedKeys:
91       - {{ .Values.userData.sshAuthorizedKey }}
92       sudo: "ALL=(ALL) NOPASSWD:ALL"
93       groups: sudo # Necessary to allow SSH logins (see /etc/ssh/sshd_config)
94     - name: root
95       sshAuthorizedKeys:
96       - {{ .Values.userData.sshAuthorizedKey }}
97   machineTemplate:
98     infrastructureRef:
99       apiVersion: infrastructure.cluster.x-k8s.io/v1alpha5
100       kind: Metal3MachineTemplate
101       name: {{ .Values.clusterName }}-controlplane
102     nodeDrainTimeout: 0s
103   replicas: {{ .Values.numControlPlaneMachines }}
104   rolloutStrategy:
105     rollingUpdate:
106       maxSurge: 1
107     type: RollingUpdate
108   version: {{ .Values.k8sVersion }}