Skip to content

Commit 41c8459

Browse files
committed
Generating join configs with kubeadm-join-config
1 parent f910b32 commit 41c8459

File tree

1 file changed

+29
-8
lines changed

1 file changed

+29
-8
lines changed

scripts/join-config.sh

+29-8
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,42 @@
33
set -euo pipefail
44

55
API_SERVER_ENDPOINT=$(kubectl config view -o jsonpath='{.clusters[0].cluster.server}' | sed s/'http[s]\?:\/\/'//)
6-
TOKEN=$(kubeadm token list -o jsonpath='{.token}')
6+
TOKEN=$(kubeadm token create)
77
CA_CERT_HASH="sha256:$(openssl x509 -pubkey -in /etc/kubernetes/pki/ca.crt | openssl ec -pubin -outform der 2>/dev/null | sha256sum | cut -d' ' -f1)"
88

99
echo "Generating kubeadm-join.yaml config..."
1010

11-
cat config/kubeadm-join.tpl.yaml | \
12-
sed "s/{{API_SERVER_ENDPOINT}}/$API_SERVER_ENDPOINT/g" | \
13-
sed "s/{{TOKEN}}/$TOKEN/g" | \
14-
sed "s/{{CA_CERT_HASH}}/$CA_CERT_HASH/g" > config/kubeadm-join.yaml
11+
kubeadm-join-config --config-path ./config/kubeadm-join.compute.yaml \
12+
--api-server-endpoint $API_SERVER_ENDPOINT \
13+
--token $TOKEN \
14+
--ca-cert-hash $CA_CERT_HASH \
15+
--label-key node.mmontes.io/type \
16+
--label-value compute
17+
18+
kubeadm-join-config --config-path ./config/kubeadm-join.compute-small.yaml \
19+
--api-server-endpoint $API_SERVER_ENDPOINT \
20+
--token $TOKEN \
21+
--ca-cert-hash $CA_CERT_HASH \
22+
--label-key node.mmontes.io/type \
23+
--label-value compute-small
24+
25+
kubeadm-join-config --config-path ./config/kubeadm-join.storage.yaml \
26+
--api-server-endpoint $API_SERVER_ENDPOINT \
27+
--token $TOKEN \
28+
--ca-cert-hash $CA_CERT_HASH \
29+
--label-key node.mmontes.io/type \
30+
--label-value storage \
31+
--taint node.mmontes.io/storage
1532

1633
cat << EOF
1734
18-
Generated join configuration file: 'config/kubeadm-join.yaml'
19-
Copy this file to each worker node and run this command to join the cluster:
35+
Generated join configuration files:
36+
- 'config/kubeadm-join.compute.yaml'
37+
- 'config/kubeadm-join.compute-small.yaml'
38+
- 'config/kubeadm-join.storage.yaml'
2039
21-
sudo bash worker.sh
40+
Copy these file to each worker node and run this command to join the cluster:
41+
42+
sudo bash node.sh 'config/kubeadm-join.compute.yaml'
2243
2344
EOF

0 commit comments

Comments
 (0)