Created
January 11, 2024 11:51
-
-
Save alexolinux/bc5495c09f7acd146e7c0c87d225faf8 to your computer and use it in GitHub Desktop.
Shell script to automate the k3s multi-nodes for both the master and worker nodes.
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 | |
| # Usage: ./install_k3s.sh [master|worker] [master_ip] | |
| if [ "$#" -lt 1 ]; then | |
| echo "Usage: $0 [master|worker] [master_ip]" | |
| exit 1 | |
| fi | |
| NODE_TYPE=$1 | |
| MASTER_IP=$2 | |
| if [ "$NODE_TYPE" == "master" ]; then | |
| # Install k3s as master | |
| curl -sfL https://get.k3s.io | K3S_KUBECONFIG_MODE="644" sh - | |
| # Print the join token | |
| sudo cat /var/lib/rancher/k3s/server/node-token | |
| else | |
| # Install k3s as worker | |
| if [ -z "$MASTER_IP" ]; then | |
| echo "Error: Master IP address is required for worker installation." | |
| exit 1 | |
| fi | |
| # Get the join token from the master node | |
| JOIN_TOKEN=$(ssh user@$MASTER_IP sudo cat /var/lib/rancher/k3s/server/node-token) | |
| # Install k3s as worker | |
| curl -sfL https://get.k3s.io | K3S_URL=https://$MASTER_IP:6443 K3S_TOKEN=$JOIN_TOKEN sh - | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment