infra/scripts/setup/kube_worker.sh
2024-09-03 10:32:02 -04:00

37 lines
809 B
Bash
Executable File

#! /usr/bin/env bash
# Function to display usage
usage() {
echo "Usage: $0 -n <host_name>"
exit 1
}
# Parse command-line arguments
while getopts "n:r:t:" opt; do
case $opt in
n) HOST_NAME="$OPTARG" ;;
t) JTOKEN="$OPTARG" ;;
r) ROLE="$OPTARG" ;;
*) usage ;;
esac
done
if [ -z $HOST_NAME ]; then
echo "Please provide a hostname with -n"
usage
exit
fi
if [ -z $JTOKEN ]; then
echo "Please provide the join token with -t i.e. script.sh -t sha256:63acb4dee8a6d0870f2a3312fd9091fabf443712cd2a9de74c3cf13ed33124b6"
exit
fi
SERVER_TOKEN=$(ssh ares "sudo kubeadm token create")
ssh ${HOST_NAME} "sudo kubeadm join 10.1.1.2:6443 --token ${SERVER_TOKEN} --discovery-token-ca-cert-hash $JTOKEN"
if [ ! -z $ROLE ]; then
kubectl taint node ${HOST_NAME} ${ROLE}=:NoSchedule
fi