添加 k3s 集群节点
添加 k3s 集群节点:
- master 需要通过
k3s-add-node脚本进行添加,下方是脚本内容
#!/bin/bash
set -ex
# master_addr=10.0.50.52 # static ip
# master_addr=$(hostname -I | awk '{print $1}') # internal ip
# master_addr=$(curl -Ls http://ifconfig.me/ip) # public ip
master_addr=$(hostname -I | awk '{print $1}') # vpn ip
token=$(sudo cat /var/lib/rancher/k3s/server/node-token)
version='v1.28.2+k3s1'
get_k3s_script_file='/usr/local/lighthouse/softwares/k3s/get_k3s.sh'
# get_k3s_script_file='./get_k3s.sh'
add_nodes_function() {
for node in $@; do
ssh root@"${node}" "cat | INSTALL_K3S_VERSION=${version} K3S_URL=https://${master_addr}:6443 K3S_TOKEN=${token} INSTALL_K3S_MIRROR=cn sh -s -- --node-external-ip ${node} --node-ip ${node}" < $get_k3s_script_file
done
}
case "$1" in
--help | -h | "")
echo "
This command is used to initialize the K3s worker node and add it to the cluster.
Please ensure firewall rule(TCP:6443) of master node has been allowed!
USAGE:
k3s-add-node [node_ip...]
Examples:
k3s-add-node 10.0.0.1 10.0.0.2
"
exit 0
;;
*)
echo "Please ensure firewall rule(TCP:6443) of master node has been allowed!"
add_nodes_function $@
;;
esac
- 在 master 节点执行命令
-
k3s-node-add 新节点的内网ip
- 给新加的 k3s node 配置 master 节点的内网通讯信息,方便使用 kubectl top node 查看资源信息
-
vim /etc/systemd/system/k3s-agent.service
文件最后必须要有个换行
ExecStart=/usr/local/bin/k3s \
agent \
'--node-external-ip' \
'node内网ip' \
'--node-ip' \
'node内网ip' \
修改完成后依次执行命令
-
systemctl daemon-reload -
systemctl restart k3s-agent.service
https://discuss.plugins-world.cn/post/n59Mvezj
实践记录