1
- kind : KubeadmControlPlane
2
- apiVersion : controlplane.cluster.x-k8s.io/v1beta1
1
+ apiVersion : bootstrap.cluster.x-k8s.io/v1beta1
2
+ kind : KubeadmConfigTemplate
3
3
metadata :
4
- name : " ${CLUSTER_NAME}-control-plane "
4
+ name : ${CLUSTER_NAME}-worker-a
5
5
spec :
6
- version : ${KUBERNETES_VERSION}
7
- replicas : ${CONTROL_PLANE_MACHINE_COUNT}
8
- machineTemplate :
9
- infrastructureRef :
10
- apiVersion : infrastructure.cluster.x-k8s.io/v1beta1
11
- kind : PacketMachineTemplate
12
- name : " ${CLUSTER_NAME}-control-plane"
13
- kubeadmConfigSpec :
14
- clusterConfiguration :
15
- apiServer :
16
- extraArgs :
17
- cloud-provider : external
18
- controllerManager :
19
- extraArgs :
20
- cloud-provider : external
21
- initConfiguration :
22
- nodeRegistration :
23
- kubeletExtraArgs :
24
- cloud-provider : external
25
- provider-id : " equinixmetal://{{ `{{ v1.instance_id }}` }}"
26
- joinConfiguration :
27
- nodeRegistration :
28
- ignorePreflightErrors :
29
- - DirAvailable--etc-kubernetes-manifests
30
- kubeletExtraArgs :
31
- cloud-provider : external
32
- provider-id : " equinixmetal://{{ `{{ v1.instance_id }}` }}"
33
- preKubeadmCommands :
6
+ template :
7
+ spec :
8
+ joinConfiguration :
9
+ nodeRegistration :
10
+ kubeletExtraArgs :
11
+ cloud-provider : external
12
+ provider-id : equinixmetal://{{ `{{ v1.instance_id }}` }}
13
+ preKubeadmCommands :
34
14
- |
35
15
sed -ri '/\sswap\s/s/^#?/#/' /etc/fstab
36
16
swapoff -a
51
31
apt-get update -y
52
32
apt-get remove -y docker docker-engine containerd runc
53
33
apt-get install -y apt-transport-https ca-certificates curl gnupg lsb-release linux-generic jq
54
- major_vers=$(lsb_release -r | awk '{ print $2 }' | cut -d. -f1)
55
- if [ "$major_vers" -ge 20 ]; then
56
- apt-get install -y kubetail
57
- fi
58
34
install -m 0755 -d /etc/apt/keyrings
59
35
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
60
36
MINOR_KUBERNETES_VERSION=$(echo {{ .kubernetesVersion }} | cut -d. -f1-2 )
@@ -67,91 +43,46 @@ spec:
67
43
TRIMMED_KUBERNETES_VERSION=$(echo {{ .kubernetesVersion }} | sed 's/\./\\\\./g' | sed 's/^v//')
68
44
RESOLVED_KUBERNETES_VERSION=$(apt-cache madison kubelet | awk -v VERSION=$${TRIMMED_KUBERNETES_VERSION} '$3~ VERSION { print $3 }' | head -n1)
69
45
apt-get install -y containerd.io kubelet=$${RESOLVED_KUBERNETES_VERSION} kubeadm=$${RESOLVED_KUBERNETES_VERSION} kubectl=$${RESOLVED_KUBERNETES_VERSION}
70
- containerd config default > /etc/containerd/config.toml
71
46
cat <<EOF > /etc/crictl.yaml
72
47
runtime-endpoint: unix:///run/containerd/containerd.sock
73
48
image-endpoint: unix:///run/containerd/containerd.sock
74
49
EOF
50
+ containerd config default > /etc/containerd/config.toml
75
51
sed -i 's/SystemdCgroup = false/SystemdCgroup = true/' /etc/containerd/config.toml
76
52
sed -i "s,sandbox_image.*$,sandbox_image = \"$(kubeadm config images list | grep pause | sort -r | head -n1)\"," /etc/containerd/config.toml
77
53
systemctl restart containerd
78
- ping -c 3 -q {{ .controlPlaneEndpoint }} && echo OK || ip addr add {{ .controlPlaneEndpoint }} dev lo
79
- postKubeadmCommands :
80
- - |
81
- cat <<EOF >> /etc/network/interfaces
82
- auto lo:0
83
- iface lo:0 inet static
84
- address {{ .controlPlaneEndpoint }}
85
- netmask 255.255.255.255
86
- EOF
87
- systemctl restart networking
88
- mkdir -p $HOME/.kube
89
- cp /etc/kubernetes/admin.conf $HOME/.kube/config
90
- echo "source <(kubectl completion bash)" >> $HOME/.bashrc
91
- echo "alias k=kubectl" >> $HOME/.bashrc
92
- echo "complete -o default -F __start_kubectl k" >> $HOME/.bashrc
93
- if [ -f "/run/kubeadm/kubeadm.yaml" ]; then
94
- export KUBECONFIG=/etc/kubernetes/admin.conf
95
- export CPEM_YAML=https://github.com/equinix/cloud-provider-equinix-metal/releases/download/${CPEM_VERSION:=v3.7.0}/deployment.yaml
96
- export SECRET_DATA='cloud-sa.json=''{"apiKey": "{{ .apiKey }}","projectID": "${PROJECT_ID}", "eipTag": "cluster-api-provider-packet:cluster-id:${CLUSTER_NAME}", "eipHealthCheckUseHostIP": true}'''
97
- kubectl create secret generic -n kube-system metal-cloud-config --from-literal="$${SECRET_DATA}" || (sleep 1 && kubectl create secret generic -n kube-system metal-cloud-config --from-literal="$${SECRET_DATA}") || (sleep 1 && kubectl create secret generic -n kube-system metal-cloud-config --from-literal="$${SECRET_DATA}")
98
- kubectl apply -f $${CPEM_YAML} || (sleep 1 && kubectl apply -f $${CPEM_YAML}) || (sleep 1 && kubectl apply -f $${CPEM_YAML})
99
- fi
100
- ---
101
- apiVersion : infrastructure.cluster.x-k8s.io/v1beta1
102
- kind : PacketMachineTemplate
103
- metadata :
104
- name : " ${CLUSTER_NAME}-control-plane"
105
- spec :
106
- template :
107
- spec :
108
- os : " ${NODE_OS:=ubuntu_20_04}"
109
- billingCycle : hourly
110
- machineType : " ${CONTROLPLANE_NODE_TYPE}"
111
- sshKeys :
112
- - " ${SSH_KEY}"
113
- tags : []
114
54
---
115
55
apiVersion : cluster.x-k8s.io/v1beta1
116
56
kind : Cluster
117
57
metadata :
118
- name : " ${CLUSTER_NAME}"
58
+ name : ${CLUSTER_NAME}
119
59
spec :
120
60
clusterNetwork :
121
61
pods :
122
62
cidrBlocks :
123
- - ${POD_CIDR:=192.168.0.0/16}
63
+ - ${POD_CIDR:=192.168.0.0/16}
124
64
services :
125
65
cidrBlocks :
126
- - ${SERVICE_CIDR:=172.26.0.0/16}
127
- infrastructureRef :
128
- apiVersion : infrastructure.cluster.x-k8s.io/v1beta1
129
- kind : PacketCluster
130
- name : " ${CLUSTER_NAME}"
66
+ - ${SERVICE_CIDR:=172.26.0.0/16}
131
67
controlPlaneRef :
132
68
apiVersion : controlplane.cluster.x-k8s.io/v1beta1
133
69
kind : KubeadmControlPlane
134
- name : " ${CLUSTER_NAME}-control-plane"
135
- ---
136
- apiVersion : infrastructure.cluster.x-k8s.io/v1beta1
137
- kind : PacketCluster
138
- metadata :
139
- name : " ${CLUSTER_NAME}"
140
- spec :
141
- projectID : " ${PROJECT_ID}"
142
- metro : " ${METRO}"
143
- vipManager : " CPEM"
70
+ name : ${CLUSTER_NAME}-control-plane
71
+ infrastructureRef :
72
+ apiVersion : infrastructure.cluster.x-k8s.io/v1beta1
73
+ kind : PacketCluster
74
+ name : ${CLUSTER_NAME}
144
75
---
145
76
apiVersion : cluster.x-k8s.io/v1beta1
146
77
kind : MachineDeployment
147
78
metadata :
148
- name : ${CLUSTER_NAME}-worker-a
149
79
labels :
150
80
cluster.x-k8s.io/cluster-name : ${CLUSTER_NAME}
151
81
pool : worker-a
82
+ name : ${CLUSTER_NAME}-worker-a
152
83
spec :
153
- replicas : ${WORKER_MACHINE_COUNT}
154
84
clusterName : ${CLUSTER_NAME}
85
+ replicas : ${WORKER_MACHINE_COUNT}
155
86
selector :
156
87
matchLabels :
157
88
cluster.x-k8s.io/cluster-name : ${CLUSTER_NAME}
@@ -162,82 +93,151 @@ spec:
162
93
cluster.x-k8s.io/cluster-name : ${CLUSTER_NAME}
163
94
pool : worker-a
164
95
spec :
165
- version : ${KUBERNETES_VERSION}
166
- clusterName : ${CLUSTER_NAME}
167
96
bootstrap :
168
97
configRef :
169
- name : ${CLUSTER_NAME}-worker-a
170
98
apiVersion : bootstrap.cluster.x-k8s.io/v1beta1
171
99
kind : KubeadmConfigTemplate
100
+ name : ${CLUSTER_NAME}-worker-a
101
+ clusterName : ${CLUSTER_NAME}
172
102
infrastructureRef :
173
- name : ${CLUSTER_NAME}-worker-a
174
103
apiVersion : infrastructure.cluster.x-k8s.io/v1beta1
175
104
kind : PacketMachineTemplate
105
+ name : ${CLUSTER_NAME}-worker-a
106
+ version : ${KUBERNETES_VERSION}
107
+ ---
108
+ apiVersion : controlplane.cluster.x-k8s.io/v1beta1
109
+ kind : KubeadmControlPlane
110
+ metadata :
111
+ name : ${CLUSTER_NAME}-control-plane
112
+ spec :
113
+ kubeadmConfigSpec :
114
+ clusterConfiguration :
115
+ apiServer :
116
+ extraArgs :
117
+ cloud-provider : external
118
+ controllerManager :
119
+ extraArgs :
120
+ cloud-provider : external
121
+ initConfiguration :
122
+ nodeRegistration :
123
+ kubeletExtraArgs :
124
+ cloud-provider : external
125
+ provider-id : equinixmetal://{{ `{{ v1.instance_id }}` }}
126
+ joinConfiguration :
127
+ nodeRegistration :
128
+ ignorePreflightErrors :
129
+ - DirAvailable--etc-kubernetes-manifests
130
+ kubeletExtraArgs :
131
+ cloud-provider : external
132
+ provider-id : equinixmetal://{{ `{{ v1.instance_id }}` }}
133
+ postKubeadmCommands :
134
+ - |
135
+ cat <<EOF >> /etc/network/interfaces
136
+ auto lo:0
137
+ iface lo:0 inet static
138
+ address {{ .controlPlaneEndpoint }}
139
+ netmask 255.255.255.255
140
+ EOF
141
+ systemctl restart networking
142
+ mkdir -p $HOME/.kube
143
+ cp /etc/kubernetes/admin.conf $HOME/.kube/config
144
+ echo "source <(kubectl completion bash)" >> $HOME/.bashrc
145
+ echo "alias k=kubectl" >> $HOME/.bashrc
146
+ echo "complete -o default -F __start_kubectl k" >> $HOME/.bashrc
147
+ if [ -f "/run/kubeadm/kubeadm.yaml" ]; then
148
+ export KUBECONFIG=/etc/kubernetes/admin.conf
149
+ export CPEM_YAML=https://github.com/equinix/cloud-provider-equinix-metal/releases/download/${CPEM_VERSION:=v3.7.0}/deployment.yaml
150
+ export SECRET_DATA='cloud-sa.json=''{"apiKey": "{{ .apiKey }}","projectID": "${PROJECT_ID}", "eipTag": "cluster-api-provider-packet:cluster-id:${CLUSTER_NAME}", "eipHealthCheckUseHostIP": true}'''
151
+ kubectl create secret generic -n kube-system metal-cloud-config --from-literal="$${SECRET_DATA}" || (sleep 1 && kubectl create secret generic -n kube-system metal-cloud-config --from-literal="$${SECRET_DATA}") || (sleep 1 && kubectl create secret generic -n kube-system metal-cloud-config --from-literal="$${SECRET_DATA}")
152
+ kubectl apply -f $${CPEM_YAML} || (sleep 1 && kubectl apply -f $${CPEM_YAML}) || (sleep 1 && kubectl apply -f $${CPEM_YAML})
153
+ fi
154
+ preKubeadmCommands :
155
+ - |
156
+ sed -ri '/\sswap\s/s/^#?/#/' /etc/fstab
157
+ swapoff -a
158
+ mount -a
159
+ cat <<EOF > /etc/modules-load.d/containerd.conf
160
+ overlay
161
+ br_netfilter
162
+ EOF
163
+ modprobe overlay
164
+ modprobe br_netfilter
165
+ cat <<EOF > /etc/sysctl.d/99-kubernetes-cri.conf
166
+ net.bridge.bridge-nf-call-iptables = 1
167
+ net.ipv4.ip_forward = 1
168
+ net.bridge.bridge-nf-call-ip6tables = 1
169
+ EOF
170
+ sysctl --system
171
+ export DEBIAN_FRONTEND=noninteractive
172
+ apt-get update -y
173
+ apt-get remove -y docker docker-engine containerd runc
174
+ apt-get install -y apt-transport-https ca-certificates curl gnupg lsb-release linux-generic jq
175
+ major_vers=$(lsb_release -r | awk '{ print $2 }' | cut -d. -f1)
176
+ if [ "$major_vers" -ge 20 ]; then
177
+ apt-get install -y kubetail
178
+ fi
179
+ install -m 0755 -d /etc/apt/keyrings
180
+ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
181
+ MINOR_KUBERNETES_VERSION=$(echo {{ .kubernetesVersion }} | cut -d. -f1-2 )
182
+ curl -fsSL https://pkgs.k8s.io/core:/stable:/$${MINOR_KUBERNETES_VERSION}/deb/Release.key | gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
183
+ chmod a+r /etc/apt/keyrings/docker.gpg
184
+ chmod a+r /etc/apt/keyrings/kubernetes-archive-keyring.gpg
185
+ echo "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" > /etc/apt/sources.list.d/docker.list
186
+ echo "deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/$${MINOR_KUBERNETES_VERSION}/deb/ /" > /etc/apt/sources.list.d/kubernetes.list
187
+ apt-get update -y
188
+ TRIMMED_KUBERNETES_VERSION=$(echo {{ .kubernetesVersion }} | sed 's/\./\\\\./g' | sed 's/^v//')
189
+ RESOLVED_KUBERNETES_VERSION=$(apt-cache madison kubelet | awk -v VERSION=$${TRIMMED_KUBERNETES_VERSION} '$3~ VERSION { print $3 }' | head -n1)
190
+ apt-get install -y containerd.io kubelet=$${RESOLVED_KUBERNETES_VERSION} kubeadm=$${RESOLVED_KUBERNETES_VERSION} kubectl=$${RESOLVED_KUBERNETES_VERSION}
191
+ containerd config default > /etc/containerd/config.toml
192
+ cat <<EOF > /etc/crictl.yaml
193
+ runtime-endpoint: unix:///run/containerd/containerd.sock
194
+ image-endpoint: unix:///run/containerd/containerd.sock
195
+ EOF
196
+ sed -i 's/SystemdCgroup = false/SystemdCgroup = true/' /etc/containerd/config.toml
197
+ sed -i "s,sandbox_image.*$,sandbox_image = \"$(kubeadm config images list | grep pause | sort -r | head -n1)\"," /etc/containerd/config.toml
198
+ systemctl restart containerd
199
+ ping -c 3 -q {{ .controlPlaneEndpoint }} && echo OK || ip addr add {{ .controlPlaneEndpoint }} dev lo
200
+ machineTemplate :
201
+ infrastructureRef :
202
+ apiVersion : infrastructure.cluster.x-k8s.io/v1beta1
203
+ kind : PacketMachineTemplate
204
+ name : ${CLUSTER_NAME}-control-plane
205
+ replicas : ${CONTROL_PLANE_MACHINE_COUNT}
206
+ version : ${KUBERNETES_VERSION}
207
+ ---
208
+ apiVersion : infrastructure.cluster.x-k8s.io/v1beta1
209
+ kind : PacketCluster
210
+ metadata :
211
+ name : ${CLUSTER_NAME}
212
+ spec :
213
+ metro : ${METRO}
214
+ projectID : ${PROJECT_ID}
215
+ vipManager : CPEM
176
216
---
177
217
apiVersion : infrastructure.cluster.x-k8s.io/v1beta1
178
218
kind : PacketMachineTemplate
179
219
metadata :
180
- name : ${CLUSTER_NAME}-worker-a
220
+ name : ${CLUSTER_NAME}-control-plane
181
221
spec :
182
222
template :
183
223
spec :
184
- os : " ${NODE_OS:=ubuntu_20_04}"
185
224
billingCycle : hourly
186
- machineType : " ${WORKER_NODE_TYPE}"
225
+ machineType : ${CONTROLPLANE_NODE_TYPE}
226
+ os : ${NODE_OS:=ubuntu_20_04}
187
227
sshKeys :
188
- - " ${SSH_KEY}"
228
+ - ${SSH_KEY}
189
229
tags : []
190
230
---
191
- kind : KubeadmConfigTemplate
192
- apiVersion : bootstrap.cluster.x-k8s.io/v1beta1
231
+ apiVersion : infrastructure.cluster.x-k8s.io/v1beta1
232
+ kind : PacketMachineTemplate
193
233
metadata :
194
- name : " ${CLUSTER_NAME}-worker-a"
234
+ name : ${CLUSTER_NAME}-worker-a
195
235
spec :
196
236
template :
197
237
spec :
198
- joinConfiguration :
199
- nodeRegistration :
200
- kubeletExtraArgs :
201
- cloud-provider : external
202
- provider-id : " equinixmetal://{{ `{{ v1.instance_id }}` }}"
203
- preKubeadmCommands :
204
- - |
205
- sed -ri '/\sswap\s/s/^#?/#/' /etc/fstab
206
- swapoff -a
207
- mount -a
208
- cat <<EOF > /etc/modules-load.d/containerd.conf
209
- overlay
210
- br_netfilter
211
- EOF
212
- modprobe overlay
213
- modprobe br_netfilter
214
- cat <<EOF > /etc/sysctl.d/99-kubernetes-cri.conf
215
- net.bridge.bridge-nf-call-iptables = 1
216
- net.ipv4.ip_forward = 1
217
- net.bridge.bridge-nf-call-ip6tables = 1
218
- EOF
219
- sysctl --system
220
- export DEBIAN_FRONTEND=noninteractive
221
- apt-get update -y
222
- apt-get remove -y docker docker-engine containerd runc
223
- apt-get install -y apt-transport-https ca-certificates curl gnupg lsb-release linux-generic jq
224
- install -m 0755 -d /etc/apt/keyrings
225
- curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
226
- MINOR_KUBERNETES_VERSION=$(echo {{ .kubernetesVersion }} | cut -d. -f1-2 )
227
- curl -fsSL https://pkgs.k8s.io/core:/stable:/$${MINOR_KUBERNETES_VERSION}/deb/Release.key | gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
228
- chmod a+r /etc/apt/keyrings/docker.gpg
229
- chmod a+r /etc/apt/keyrings/kubernetes-archive-keyring.gpg
230
- echo "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" > /etc/apt/sources.list.d/docker.list
231
- echo "deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/$${MINOR_KUBERNETES_VERSION}/deb/ /" > /etc/apt/sources.list.d/kubernetes.list
232
- apt-get update -y
233
- TRIMMED_KUBERNETES_VERSION=$(echo {{ .kubernetesVersion }} | sed 's/\./\\\\./g' | sed 's/^v//')
234
- RESOLVED_KUBERNETES_VERSION=$(apt-cache madison kubelet | awk -v VERSION=$${TRIMMED_KUBERNETES_VERSION} '$3~ VERSION { print $3 }' | head -n1)
235
- apt-get install -y containerd.io kubelet=$${RESOLVED_KUBERNETES_VERSION} kubeadm=$${RESOLVED_KUBERNETES_VERSION} kubectl=$${RESOLVED_KUBERNETES_VERSION}
236
- cat <<EOF > /etc/crictl.yaml
237
- runtime-endpoint: unix:///run/containerd/containerd.sock
238
- image-endpoint: unix:///run/containerd/containerd.sock
239
- EOF
240
- containerd config default > /etc/containerd/config.toml
241
- sed -i 's/SystemdCgroup = false/SystemdCgroup = true/' /etc/containerd/config.toml
242
- sed -i "s,sandbox_image.*$,sandbox_image = \"$(kubeadm config images list | grep pause | sort -r | head -n1)\"," /etc/containerd/config.toml
243
- systemctl restart containerd
238
+ billingCycle : hourly
239
+ machineType : ${WORKER_NODE_TYPE}
240
+ os : ${NODE_OS:=ubuntu_20_04}
241
+ sshKeys :
242
+ - ${SSH_KEY}
243
+ tags : []
0 commit comments