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 集群】
推荐阅读
- 使用 kube-downscaler 降低 Kubernetes 集群成本
- Linux上使用Docker实现应用程序打包和分发
- Rust 编译为WebAssembly 在前端项目中使用
- 如何使用 Python 和 python-docx 库读取、写入和操作 Word 文件
- 如何使用GPT作为SQL查询引擎的自然语言
- 火山石的作用及使用方法详解 火山石的作用
- 怎样使用支付宝花呗 怎样使用支付宝
- 这几款水乳特别适合油皮、痘肌使用,有效消灭闭口小痘痘效果好
- 油漆喷枪使用 油漆喷枪的注意事项
- cdr里怎么创建剪切蒙版,cdr中的剪切蒙版要怎么样使用