在本系列的上一篇文章中, 我们实践了如何搭建K3s集群的及Master服务器,现在,我们要为集群加入一个新的工作节点。
获取集群节点Token
为了提高集群的安全性,要想将节点加入道集群中,必须首先获取该集群的”K3S_TOKEN”,该token保存于Master节点中的 /var/lib/rancher/k3s/server/node-token 文件中。
登录在 上一篇文章 中建立的 Master 节点。执行:
1
| sudo cat /var/lib/rancher/k3s/server/node-token
|
系统将输出node-token文件中的token值,在本练习中,在我的环境中产生的值为:
1
| K104abc161f0c6250f23833dcf74260c09a9654bb9bac39eddd94147d44e61ebfde::server:bac1353e4f7a2df733a152f6c121d3bb
|
加入工作节点
获取了 token 后,登录到准备加入的工作节点中,顺序执行以下命令:
- 更新操作系统
- 以工作节点(worker node)方式安装 k3s ,并指定 Master 节点和 Token 的信息。
1
| curl --insecure -L https://get.k3s.io | K3S_URL=https://<your master>:6443 K3S_TOKEN=<your token> sh -
|
因为在课堂实验中 Master 节点的IP地址为: 192.168.1.60, 工作节点的IP地址为: 192.168.1.61, 结合上一节获取的 token 信息,则命令为:
1
| curl --insecure -L https://get.k3s.io | K3S_URL=https://192.168.1.60:6443 K3S_TOKEN=K104abc161f0c6250f23833dcf74260c09a9654bb9bac39eddd94147d44e61ebfde::server:bac1353e4f7a2df733a152f6c121d3bb sh -
|
系统显示:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- 0:00:03 --:--:-- 0 100 20968 100 20968 0 0 1864 0 0:00:11 0:00:11 --:--:-- 6040 [sudo] password for stu: [INFO] Finding latest release [INFO] Using v1.17.0+k3s.1 as release [INFO] Downloading hash https://github.com/rancher/k3s/releases/download/v1.17.0+k3s.1/sha256sum-amd64.txt [INFO] Downloading binary https://github.com/rancher/k3s/releases/download/v1.17.0+k3s.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
|
这样就完成了工作节点的安装并将其加入到集群中。 注意:在客户端启动的是 k3s agent
验证安装
登录到 Master 节点,执行:
1
| kubectl get node -o wide
|
系统将显示集群中所有节点的信息。
1 2 3
| NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME k3s-node01 Ready <none> 3m22s v1.17.0+k3s.1 192.168.1.61 <none> Ubuntu 18.04.3 LTS 4.15.0-74-generic containerd://1.3.0-k3s.5 k3s-master Ready master 10h v1.17.0+k3s.1 192.168.1.60 <none> Ubuntu 18.04.3 LTS 4.15.0-74-generic containerd://1.3.0-k3s.5
|