Skip to content

Commit

Permalink
Generating join configs with kubeadm-join-config
Browse files Browse the repository at this point in the history
  • Loading branch information
mmontes11 committed Aug 31, 2024
1 parent f910b32 commit 41c8459
Showing 1 changed file with 29 additions and 8 deletions.
37 changes: 29 additions & 8 deletions scripts/join-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,42 @@
set -euo pipefail

API_SERVER_ENDPOINT=$(kubectl config view -o jsonpath='{.clusters[0].cluster.server}' | sed s/'http[s]\?:\/\/'//)
TOKEN=$(kubeadm token list -o jsonpath='{.token}')
TOKEN=$(kubeadm token create)
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)"

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

cat config/kubeadm-join.tpl.yaml | \
sed "s/{{API_SERVER_ENDPOINT}}/$API_SERVER_ENDPOINT/g" | \
sed "s/{{TOKEN}}/$TOKEN/g" | \
sed "s/{{CA_CERT_HASH}}/$CA_CERT_HASH/g" > config/kubeadm-join.yaml
kubeadm-join-config --config-path ./config/kubeadm-join.compute.yaml \
--api-server-endpoint $API_SERVER_ENDPOINT \
--token $TOKEN \
--ca-cert-hash $CA_CERT_HASH \
--label-key node.mmontes.io/type \
--label-value compute

kubeadm-join-config --config-path ./config/kubeadm-join.compute-small.yaml \
--api-server-endpoint $API_SERVER_ENDPOINT \
--token $TOKEN \
--ca-cert-hash $CA_CERT_HASH \
--label-key node.mmontes.io/type \
--label-value compute-small

kubeadm-join-config --config-path ./config/kubeadm-join.storage.yaml \
--api-server-endpoint $API_SERVER_ENDPOINT \
--token $TOKEN \
--ca-cert-hash $CA_CERT_HASH \
--label-key node.mmontes.io/type \
--label-value storage \
--taint node.mmontes.io/storage

cat << EOF
Generated join configuration file: 'config/kubeadm-join.yaml'
Copy this file to each worker node and run this command to join the cluster:
Generated join configuration files:
- 'config/kubeadm-join.compute.yaml'
- 'config/kubeadm-join.compute-small.yaml'
- 'config/kubeadm-join.storage.yaml'
sudo bash worker.sh
Copy these file to each worker node and run this command to join the cluster:
sudo bash node.sh 'config/kubeadm-join.compute.yaml'
EOF

0 comments on commit 41c8459

Please sign in to comment.