#!/bin/bash KUBE_USER="kevin" KUBE_CP="k8s-control-plane" KUBE_W1="k8s-worker1" KUBE_W2="k8s-worker2" ANSIBLE_DIR="ansible" ## Prepare all of the nodes with k8s using the ansible playbooks I prepared ansible-playbook -i ./"$ANSIBLE_DIR"/inventory.ini ./"$ANSIBLE_DIR"/master-k8s.yaml ## Fetch the configuration from the freshly installed cluster. BEWARE THAT ANY EXISTING CONFIG WILL BE OVERWRITTEN scp "$KUBE_USER@$KUBE_CP":"$HOME"/.kube/config "$HOME"/.kube/config ## Now join the workers to the cluster JOIN_TOKEN=$(ssh "$KUBE_USER@$KUBE_CP" "kubeadm token create --print-join-command") for NODE in "$KUBE_W1" "$KUBE_W2"; do echo "Joining $NODE" ssh "$KUBE_USER@$NODE" "sudo $JOIN_TOKEN" done