k3s集群管理rancher2.3 server-agent(工作节点)安装
在server主节点部署完成之后,在server主节点的/var/lib/rancher/k3s/server/目录下面生成一个node-token文件,该文件存储了k3s agent工作节点加入集群时所需的token。
K3S_TOKEN创建在/var/lib/rancher/k3s/server/node-token
cat /var/lib/rancher/k3s/server/node-token
K1042e2f8e353b9409472c1e0cca8457abe184dc7be3f0805109e92c50c193ceb42::node:c83acbf89a7de7026d6f6928dc270028
每台主机必须具有唯一的主机名。如果您的主机没有唯一的主机名,请传递K3S_NODE_NAME环境变量,为每个主机提供一个唯一有效的主机名。
hostnamectl set-hostname 192.168.6.125
添加worker节点:
curl -sfL https://docs.rancher.cn/k3s/k3s-install.sh | INSTALL_K3S_MIRROR=cn K3S_URL=https://主节点IP地址:6443 K3S_TOKEN=主节点的token sh -
安装输出:
[INFO] Finding latest release
[INFO] Using v0.8.1 as release
[INFO] Downloading hash https://github.com/rancher/k3s/releases/download/v0.8.1/sha256sum-amd64.txt
[INFO] Downloading binary https://github.com/rancher/k3s/releases/download/v0.8.1/k3s
[INFO] Verifying binary download
[INFO] Installing k3s to /usr/local/bin/k3s
[INFO] Creating /usr/local/bin/kubectl symlink to k3s
[INFO] Creating /usr/local/bin/crictl symlink to k3s
[INFO] Creating /usr/local/bin/ctr symlink to k3s
[INFO] Creating killall script /usr/local/bin/k3s-killall.sh
[INFO] Creating uninstall script /usr/local/bin/k3s-agent-uninstall.sh
[INFO] env: Creating environment file /etc/systemd/system/k3s-agent.service.env
[INFO] systemd: Creating service file /etc/systemd/system/k3s-agent.service
[INFO] systemd: Enabling k3s-agent unit
Created symlink /etc/systemd/system/multi-user.target.wants/k3s-agent.service → /etc/systemd/system/k3s-agent.service.
[INFO] systemd: Starting k3s-agent
验证安装:
systemctl status k3s-agent
如果 Active: active (running) 说明启动成功
进入k3s server 主节点的服务器查看子节点是否添加成功
kubectl get nodes
如果列出了 agent 的节点说明安装成功,如果没有请检查 url 和 token 是否正确,并检查 agent 和 server 的网络是否能相互连接,还有就是 server 的防火墙是否打开了 6443端口
查看agent工作节点是否已经加入到了集群中:
k3s kubectl get nodes
NAME STATUS ROLES AGE VERSION
test01-201 Ready master 12h v1.15.4-k3s.1
test02-202 Ready worker 11h v1.15.4-k3s.1
可以看到节点已经成功加入到了集群中。
调整K3S工作节点的服务配置文件,以将K3S的默认容器引擎从Containerd切换到Docker。
修改K3S工作节点服务的配置文件:
vim /etc/systemd/system/multi-user.target.wants/k3s-agent.service
service k3s-agent restart
在这里我们需要修改ExecStart的值,将其修改为:
/usr/local/bin/k3s-agent server --docker --no-deploy traefik
之后保存退出,执行命令重新加载新的服务配置文件:
systemctl daemon-reload
完成后重启K3S-agent服务:
service k3s-agent restart
检查pod的状态:
k3s kubectl get po --all-namespaces
NAMESPACE NAME READY STATUS RESTARTS AGE
kube-system svclb-traefik-9x9d8 2/2 Running 0 15h
cattle-system cattle-node-agent-zmxvg 1/1 Running 0 15h
kube-system svclb-traefik-zdm8v 2/2 Running 0 5m11s
cattle-system cattle-node-agent-2xhzx 1/1 Running 0 5m11s
kube-system local-path-provisioner-58fb86bdfd-q6klf 1/1 Running 0 91s
kube-system metrics-server-6d684c7b5-l5kts 1/1 Running 0 91s
cattle-system cattle-cluster-agent-768f7755c9-knjg8 1/1 Running 0 91s
kube-system coredns-6c6bb68b64-kjrgd 1/1 Running 0 91s
kube-system traefik-7b8b884c8-dk4t7 1/1 Running 0 91s
可以看到,系统命名空间下所有的应用都已经启动了,server节点已经就绪,接下来可以部署k3s agent工作节点了。
附件 |
k3s-(3)k3s-agent工作节点安装.docx |