Created
March 13, 2025 18:13
-
-
Save itsjimbo/4524005e1b6f886cbd6bb0640440c48a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
source 0__base_include.sh | |
GREEN='\033[0;32m' | |
LB='\033[1;34m' # light blue | |
NC='\033[0m' # No Color | |
echo "############################################################################" | |
echo "Now deploying k3s cluster - ${CLUSTER_NAME} on multipass VMs" | |
echo -e "[${LB}Info${NC}] deploy k3s on $CLUSTER_NAME" | |
multipass exec ${CLUSTER_NAME}-master -- /bin/bash -c "curl -sfL https://get.k3s.io | CLUSTER_NAME=${CLUSTER_NAME} sh ${K3S_OPTIONS}" | grep Using | |
# Get the IP of the master node | |
K3S_NODEIP_MASTER="https://$(multipass info ${CLUSTER_NAME}-master | grep "IPv4" | awk -F' ' '{print $2}'):6443" | |
# Get the TOKEN from the master node | |
K3S_TOKEN="$(multipass exec ${CLUSTER_NAME}-master -- /bin/bash -c "sudo cat /var/lib/rancher/k3s/server/node-token")" | |
# Deploy k3s on the worker nodes node2,node3,node4 | |
WORKERS=$(echo $(multipass list | grep ${CLUSTER_NAME}-worker | awk '{print $1}')) | |
for WORKER in ${WORKERS}; | |
do echo -e "[${LB}Info${NC}] deploy k3s on ${WORKER}" && multipass exec ${WORKER} -- /bin/bash -c "curl -sfL https://get.k3s.io | K3S_TOKEN=${K3S_TOKEN} K3S_URL=${K3S_NODEIP_MASTER} sh -" | grep -w "Using"; | |
done | |
sleep 10 | |
echo "############################################################################" | |
echo exporting KUBECONFIG file from master node | |
multipass exec ${CLUSTER_NAME}-master -- bash -c 'sudo cat /etc/rancher/k3s/k3s.yaml' > ${CLUSTER_NAME}.yaml | |
sed -i'.back' -e "s/127.0.0.1/${CLUSTER_NAME}-master/g" ${CLUSTER_NAME}.yaml | |
export KUBECONFIG=`pwd`/${CLUSTER_NAME}.yaml && echo -e "[${LB}Info${NC}] setting KUBECONFIG=${KUBECONFIG}" | |
echo -e "[${LB}Info${NC}] tainting master node: ${CLUSTER_NAME}-master" | |
# download latest kubectl to /usr/local/bin? | |
#curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/darwin/arm64/kubectl" | |
#chmod 755 kubectl | |
#sudo mv kubectl /usr/local/bin | |
kubectl taint node ${CLUSTER_NAME}-master node-role.kubernetes.io/master=effect:NoSchedule | |
for WORKER in ${WORKERS}; do kubectl label node ${WORKER} node-role.kubernetes.io/node= > /dev/null && echo -e "[${LB}Info${NC}] label ${WORKER} with node"; done | |
kubectl get nodes | |
echo "are the nodes ready?" | |
echo "if you face problems, please open an issue on github" | |
echo -e "[${GREEN}FINISHED${NC}]" | |
echo "############################################################################" | |
export KUBECONFIG=${CLUSTER_NAME}.yaml |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment