-
Notifications
You must be signed in to change notification settings - Fork 204
/
provider-components.yaml.template
381 lines (365 loc) · 13.4 KB
/
provider-components.yaml.template
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: clusterapi-controllers
labels:
api: clusterapi
spec:
replicas: 1
template:
metadata:
labels:
api: clusterapi
spec:
nodeSelector:
node-role.kubernetes.io/master: ""
tolerations:
- effect: NoSchedule
key: node-role.kubernetes.io/master
- key: CriticalAddonsOnly
operator: Exists
- effect: NoExecute
key: node.alpha.kubernetes.io/notReady
operator: Exists
- effect: NoExecute
key: node.alpha.kubernetes.io/unreachable
operator: Exists
containers:
- name: controller-manager
image: gcr.io/k8s-cluster-api/controller-manager:0.0.7
volumeMounts:
- name: config
mountPath: /etc/kubernetes
- name: certs
mountPath: /etc/ssl/certs
command:
- "./controller-manager"
args:
- --kubeconfig=/etc/kubernetes/admin.conf
resources:
requests:
cpu: 100m
memory: 20Mi
limits:
cpu: 100m
memory: 30Mi
- name: gce-machine-controller
image: gcr.io/k8s-cluster-api/gce-controller:0.0.15
volumeMounts:
- name: config
mountPath: /etc/kubernetes
- name: certs
mountPath: /etc/ssl/certs
- name: credentials
mountPath: /etc/credentials
- name: sshkeys
mountPath: /etc/sshkeys
- name: machine-setup
mountPath: /etc/machinesetup
- name: kubeadm
mountPath: /usr/bin/kubeadm
env:
- name: GOOGLE_APPLICATION_CREDENTIALS
value: /etc/credentials/service-account.json
- name: NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
command:
- "./gce-controller"
args:
- --kubeconfig=/etc/kubernetes/admin.conf
- --machinesetup=/etc/machinesetup/machine_setup_configs.yaml
- --controller=machine
resources:
requests:
cpu: 100m
memory: 20Mi
limits:
cpu: 100m
memory: 30Mi
- name: gce-cluster-controller
image: gcr.io/k8s-cluster-api/gce-controller:0.0.15
volumeMounts:
- name: config
mountPath: /etc/kubernetes
- name: certs
mountPath: /etc/ssl/certs
- name: credentials
mountPath: /etc/credentials
- name: sshkeys
mountPath: /etc/sshkeys
- name: machine-setup
mountPath: /etc/machinesetup
env:
- name: GOOGLE_APPLICATION_CREDENTIALS
value: /etc/credentials/service-account.json
command:
- "./gce-controller"
args:
- --kubeconfig=/etc/kubernetes/admin.conf
- --controller=cluster
resources:
requests:
cpu: 100m
memory: 20Mi
limits:
cpu: 100m
memory: 30Mi
volumes:
- name: config
hostPath:
path: /etc/kubernetes
- name: certs
hostPath:
path: /etc/ssl/certs
- name: sshkeys
secret:
secretName: machine-controller-sshkeys
defaultMode: 256
- name: credentials
secret:
secretName: machine-controller-credential
- name: machine-setup
configMap:
name: machine-setup
- name: kubeadm
hostPath:
path: /usr/bin/kubeadm
---
apiVersion: v1
kind: Secret
type: Opaque
metadata:
name: machine-controller-sshkeys
namespace: default
data:
user: $MACHINE_CONTROLLER_SSH_USER
private: $MACHINE_CONTROLLER_SSH_PRIVATE
# In-place master upgrade will not work till after https://github.com/kubernetes-sigs/cluster-api/issues/160
public: $MACHINE_CONTROLLER_SSH_PUBLIC
---
apiVersion: v1
kind: Secret
type: Opaque
metadata:
name: machine-controller-credential
namespace: default
data:
service-account.json: $MACHINE_CONTROLLER_SA_KEY
---
apiVersion: v1
kind: ConfigMap
metadata:
name: machine-setup
data:
machine_setup_configs.yaml: |-
items:
- machineParams:
- os: ubuntu-1604-lts
roles:
- Master
versions:
kubelet: 1.9.4
controlPlane: 1.9.4
image: projects/ubuntu-os-cloud/global/images/family/ubuntu-1604-lts
metadata:
startupScript: |
set -e
set -x
(
ARCH=amd64
function curl_metadata() {
curl --retry 5 --silent --fail --header "Metadata-Flavor: Google" "http://metadata/computeMetadata/v1/instance/$@"
}
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
touch /etc/apt/sources.list.d/kubernetes.list
sh -c 'echo "deb http://apt.kubernetes.io/ kubernetes-xenial main" > /etc/apt/sources.list.d/kubernetes.list'
apt-get update -y
apt-get install -y \
socat \
ebtables \
apt-transport-https \
cloud-utils \
prips
function install_configure_docker () {
# prevent docker from auto-starting
echo "exit 101" > /usr/sbin/policy-rc.d
chmod +x /usr/sbin/policy-rc.d
trap "rm /usr/sbin/policy-rc.d" RETURN
apt-get install -y docker.io
echo 'DOCKER_OPTS="--iptables=false --ip-masq=false"' > /etc/default/docker
systemctl daemon-reload
systemctl enable docker
systemctl start docker
}
install_configure_docker
curl -sSL https://dl.k8s.io/release/${VERSION}/bin/linux/${ARCH}/kubeadm > /usr/bin/kubeadm.dl
chmod a+rx /usr/bin/kubeadm.dl
# kubeadm uses 10th IP as DNS server
CLUSTER_DNS_SERVER=$(prips ${SERVICE_CIDR} | head -n 11 | tail -n 1)
# Our Debian packages have versions like "1.8.0-00" or "1.8.0-01". Do a prefix
# search based on our SemVer to find the right (newest) package version.
function getversion() {
name=$1
prefix=$2
version=$(apt-cache madison $name | awk '{ print $3 }' | grep ^$prefix | head -n1)
if [[ -z "$version" ]]; then
echo Can\'t find package $name with prefix $prefix
exit 1
fi
echo $version
}
KUBELET=$(getversion kubelet ${KUBELET_VERSION}-)
KUBEADM=$(getversion kubeadm ${KUBELET_VERSION}-)
apt-get install -y \
kubelet=${KUBELET} \
kubeadm=${KUBEADM}
mv /usr/bin/kubeadm.dl /usr/bin/kubeadm
chmod a+rx /usr/bin/kubeadm
# Override network args to use kubenet instead of cni, override Kubelet DNS args and
# add cloud provider args.
cat > /etc/systemd/system/kubelet.service.d/20-kubenet.conf <<EOF
[Service]
Environment="KUBELET_NETWORK_ARGS=--network-plugin=kubenet"
Environment="KUBELET_DNS_ARGS=--cluster-dns=${CLUSTER_DNS_SERVER} --cluster-domain=${CLUSTER_DNS_DOMAIN}"
Environment="KUBELET_EXTRA_ARGS=--cloud-provider=gce --cloud-config=/etc/kubernetes/cloud-config"
EOF
systemctl daemon-reload
systemctl restart kubelet.service
PRIVATEIP=`curl_metadata "network-interfaces/0/ip"`
echo $PRIVATEIP > /tmp/.ip
PUBLICIP=`curl_metadata "network-interfaces/0/access-configs/0/external-ip"`
# Set up the GCE cloud config, which gets picked up by kubeadm init since cloudProvider is set to GCE.
cat > /etc/kubernetes/cloud-config <<EOF
[global]
project-id = ${PROJECT}
network-name = ${NETWORK}
subnetwork-name = ${SUBNETWORK}
node-tags = ${NODE_TAG}
EOF
# Set up kubeadm config file to pass parameters to kubeadm init.
cat > /etc/kubernetes/kubeadm_config.yaml <<EOF
apiVersion: kubeadm.k8s.io/v1alpha1
kind: MasterConfiguration
api:
advertiseAddress: ${PUBLICIP}
bindPort: ${PORT}
networking:
serviceSubnet: ${SERVICE_CIDR}
kubernetesVersion: v${CONTROL_PLANE_VERSION}
cloudProvider: gce
token: ${TOKEN}
controllerManagerExtraArgs:
cluster-cidr: ${POD_CIDR}
service-cluster-ip-range: ${SERVICE_CIDR}
allocate-node-cidrs: "true"
apiServerCertSANs:
- ${PUBLICIP}
- ${PRIVATEIP}
EOF
function install_certificates () {
if ! curl_metadata "attributes/ca-cert"; then
return
fi
echo "Configuring custom certificate authority..."
PKI_PATH=/etc/kubernetes/pki
mkdir -p ${PKI_PATH}
CA_CERT_PATH=${PKI_PATH}/ca.crt
curl_metadata "attributes/ca-cert" | base64 -d > ${CA_CERT_PATH}
chmod 0644 ${CA_CERT_PATH}
CA_KEY_PATH=${PKI_PATH}/ca.key
curl_metadata "attributes/ca-key" | base64 -d > ${CA_KEY_PATH}
chmod 0600 ${CA_KEY_PATH}
}
# Create and set bridge-nf-call-iptables to 1 to pass the kubeadm preflight check.
# Workaround was found here:
# http://zeeshanali.com/sysadmin/fixed-sysctl-cannot-stat-procsysnetbridgebridge-nf-call-iptables/
modprobe br_netfilter
install_certificates
kubeadm init --config /etc/kubernetes/kubeadm_config.yaml
for tries in $(seq 1 60); do
kubectl --kubeconfig /etc/kubernetes/kubelet.conf annotate --overwrite node $(hostname) machine=${MACHINE} && break
sleep 1
done
echo done.
) 2>&1 | tee /var/log/startup.log
- machineParams:
- os: ubuntu-1604-lts
roles:
- Node
versions:
kubelet: 1.9.4
image: projects/ubuntu-os-cloud/global/images/family/ubuntu-1604-lts
metadata:
startupScript: |
set -e
set -x
(
apt-get update
apt-get install -y apt-transport-https prips
apt-key adv --keyserver hkp://keyserver.ubuntu.com --recv-keys F76221572C52609D
cat <<EOF > /etc/apt/sources.list.d/k8s.list
deb [arch=amd64] https://apt.dockerproject.org/repo ubuntu-xenial main
EOF
apt-get update
function install_configure_docker () {
# prevent docker from auto-starting
echo "exit 101" > /usr/sbin/policy-rc.d
chmod +x /usr/sbin/policy-rc.d
trap "rm /usr/sbin/policy-rc.d" RETURN
apt-get install -y docker-engine=1.12.0-0~xenial
echo 'DOCKER_OPTS="--iptables=false --ip-masq=false"' > /etc/default/docker
systemctl daemon-reload
systemctl enable docker
systemctl start docker
}
install_configure_docker
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
cat <<EOF > /etc/apt/sources.list.d/kubernetes.list
deb http://apt.kubernetes.io/ kubernetes-xenial main
EOF
apt-get update
mkdir -p /etc/kubernetes/
cat > /etc/kubernetes/cloud-config <<EOF
[global]
project-id = ${PROJECT}
network-name = ${NETWORK}
subnetwork-name = ${SUBNETWORK}
node-tags = ${NODE_TAG}
EOF
# Our Debian packages have versions like "1.8.0-00" or "1.8.0-01". Do a prefix
# search based on our SemVer to find the right (newest) package version.
function getversion() {
name=$1
prefix=$2
version=$(apt-cache madison $name | awk '{ print $3 }' | grep ^$prefix | head -n1)
if [[ -z "$version" ]]; then
echo Can\'t find package $name with prefix $prefix
exit 1
fi
echo $version
}
KUBELET=$(getversion kubelet ${KUBELET_VERSION}-)
KUBEADM=$(getversion kubeadm ${KUBELET_VERSION}-)
KUBECTL=$(getversion kubectl ${KUBELET_VERSION}-)
apt-get install -y kubelet=${KUBELET} kubeadm=${KUBEADM} kubectl=${KUBECTL}
# kubeadm uses 10th IP as DNS server
CLUSTER_DNS_SERVER=$(prips ${SERVICE_CIDR} | head -n 11 | tail -n 1)
# Override network args to use kubenet instead of cni, override Kubelet DNS args and
# add cloud provider args.
cat > /etc/systemd/system/kubelet.service.d/20-kubenet.conf <<EOF
[Service]
Environment="KUBELET_NETWORK_ARGS=--network-plugin=kubenet"
Environment="KUBELET_DNS_ARGS=--cluster-dns=${CLUSTER_DNS_SERVER} --cluster-domain=${CLUSTER_DNS_DOMAIN}"
Environment="KUBELET_EXTRA_ARGS=--cloud-provider=gce --cloud-config=/etc/kubernetes/cloud-config"
EOF
systemctl daemon-reload
systemctl restart kubelet.service
kubeadm join --token "${TOKEN}" "${MASTER}" --ignore-preflight-errors=all --discovery-token-unsafe-skip-ca-verification
for tries in $(seq 1 60); do
kubectl --kubeconfig /etc/kubernetes/kubelet.conf annotate --overwrite node $(hostname) machine=${MACHINE} && break
sleep 1
done
echo done.
) 2>&1 | tee /var/log/startup.log