使用 k3sup 一分钟快速搭建 K3s 集群( 二 )


export AGENT_IP=192.168.1.12k3sup join --ip $AGENT_IP --user addo --server-ip $MASTER_IP --k3s-channel v1.24 Running: k3sup joinAgent: 192.168.1.11 Server: 192.168.1.12Received node-token from 192.168.1.11.. ok.[INFO]Finding release for channel v1.24[INFO]Using v1.24.17+k3s1 as release...查看节点:
kubectl get no NAMESTATUSROLESAGEVERSIONnode-1Ready<none>43sv1.24.17+k3s1masterReadycontrol-plane,master2m58sv1.24.17+k3s1完整脚本让 ChatGPT 生成了脚本一键创建集群 , 有兴趣的小伙伴可以试试创建个双节点的集群需要多久 。我试了下,耗时 32s 左右 。
# Define IP addressesexport HOSTS="192.168.1.11 192.168.1.12"搭建集群#!/bin/bash# Read the list of IP addresses from the environment variableIP_ADDRESSES=($HOSTS)# Define the k3s versionK3S_VERSION="v1.24"# Check if there is at least one IP addressif [ ${#IP_ADDRESSES[@]} -eq 0 ]; thenecho "No IP addresses found. Please ensure the HOSTS environment variable is correctly set."exit 1fi# Install the master nodeMASTER_IP=${IP_ADDRESSES[0]}echo "Installing master node: $MASTER_IP"k3sup install --ip $MASTER_IP --user addo --k3s-channel $K3S_VERSION--k3s-extra-args '--write-kubeconfig-mode 644 --write-kubeconfig ~/.kube/config --disable traefik --disable metrics-server --disable local-storage --disable servicelb'--local-path /tmp/config# Install the other agent nodesfor i in "${!IP_ADDRESSES[@]}"; doif [ $i -ne 0 ]; thenAGENT_IP=${IP_ADDRESSES[$i]}echo "Installing agent node: $AGENT_IP"k3sup join --ip $AGENT_IP --server-ip $MASTER_IP --user addo --k3s-channel $K3S_VERSIONfidoneecho "k3s cluster installation complete."卸载集群#!/bin/bash# Read the list of IP addresses from the environment variableIP_ADDRESSES=($HOSTS)# Check if there is at least one IP addressif [ ${#IP_ADDRESSES[@]} -eq 0 ]; thenecho "No IP addresses found. Please ensure the HOSTS environment variable is correctly set."exit 1fi# Clean up the master nodeMASTER_IP=${IP_ADDRESSES[0]}echo "Cleaning up master node: $MASTER_IP"ssh -i ~/.ssh/id_rsa $MASTER_IP k3s-uninstall.sh# Clean up the other agent nodesfor i in "${!IP_ADDRESSES[@]}"; doif [ $i -ne 0 ]; thenAGENT_IP=${IP_ADDRESSES[$i]}echo "Cleaning up agent node: $AGENT_IP"ssh -i ~/.ssh/id_rsa $AGENT_IP k3s-agent-uninstall.shfidoneecho "k3s cluster cleanup complete."参考资料[1] Alfred Snippets: https://www.alfredApp.com/help/features/snippets/
[2] k3sup: https://Github.com/alexellis/k3sup

【使用 k3sup 一分钟快速搭建 K3s 集群】


推荐阅读