iT邦幫忙

第 11 屆 iThome 鐵人賽

DAY 16
0
DevOps

從開源雲到邊緣運算系列 第 16

[Day 16]K3s 叢集搭建

想必各位在昨天已經將k3s環境建置完成了,昨天的安裝應該是個輕鬆的一天吧(最好是喇www),我們今天就來個k3s叢集建立的大冒險吧(踩坑之旅有你有我),還沒建立好環境的請先去看上一篇文章,另外今天也會再協助 Raspberry Pi 平台的捧油們,我們一起來維修一些系統 cgroup 上的問題。

Server 端

  • 一樣請用 root 進行操作

官方快速安裝版本

在上一篇安裝過後,k3s 就以經在 OS 之中執行了(其實下載後就直接執行拉),這邊的 Server 會執行 Agent 角色功能的存在與同一節點之上,功能上以 kubernetes 的說法來說,就是以 Master 節點上執行 Cluster 節點的功能,允許 Pod 在 Server 節點進行調度,在快速搭建的叢集環境中,可較快進行使用。

Server 狀態查詢

k3s kubectl get nodes
  • 這邊的 status ==> Ready 代表的是 該節點為 Pod 可派送的節點,有回饋就是代表 Server 端功能正常了
    https://ithelp.ithome.com.tw/upload/images/20191002/20121071xJbgQdE8UQ.png

Server 角色分析

k3s kubectl describe nodes
  • 這邊可以發現 kubelet 在 Server 端執行,代表 Server 上也一並執行了 Agent 的功能了。
    https://ithelp.ithome.com.tw/upload/images/20191002/20121071iSfgqiVC4q.png

Github Release 安裝版本

在 官方 Release 包中,可允許將 Server / Agent 功能獨立

k3s 應用程式狀態檢查

k3s --version

https://ithelp.ithome.com.tw/upload/images/20191002/20121071h9yj8LzG9D.png

Server 與 Worker 角色共存

  • 執行 Server 端功能
k3s server

https://ithelp.ithome.com.tw/upload/images/20191002/20121071Q2mTO3u9d5.png

Server 狀態檢查

k3s kubectl get node
  • Server 啟動失敗
    https://ithelp.ithome.com.tw/upload/images/20191002/20121071Tpvegmx6Wn.png
  • Server 啟動成功
    https://ithelp.ithome.com.tw/upload/images/20191002/20121071ErinKTcsCO.png

Server 角色分析

k3s kubectl describe nodes
  • 這邊可以看到 kubelet 已在 Server 節點運行,則表示 Agent 節點的功能已在 Server 節點執行。
    https://ithelp.ithome.com.tw/upload/images/20191002/201210716f7oPq5Mxv.png

Server 背景執行

nohup k3s server > master.log > 2&>1 &
  • 這邊會看到將 k3s Server 端放置島到 OS 背景執行,並返回一個 OS 所執行的 PID。
    https://ithelp.ithome.com.tw/upload/images/20191002/20121071OemVXM6hRp.png

Server 角色獨立

k3s server --disable-agent

https://ithelp.ithome.com.tw/upload/images/20191002/20121071qLSoSY8XqM.png

Server 狀態檢查

k3s kubectl get node
  • 這邊的 NotReady 代表的是 該節點不是 Pod 可派送的節點
    https://ithelp.ithome.com.tw/upload/images/20191002/20121071W1w7YI2c87.png

Server 角色分析

k3s kubectl describe nodes
  • 這邊 kubelet 功能被關閉,代表無法經由 kubelet 介入將 Pod 調度進入節點之中。
    https://ithelp.ithome.com.tw/upload/images/20191002/201210715Xybj1A6g3.png

Server 背景執行

nohup k3s server --disable-agent > master.log > 2&>1 &
  • 這邊會看到將 k3s Server 端放置島到 OS 背景執行,並返回一個 OS 所執行的 PID。
    https://ithelp.ithome.com.tw/upload/images/20191002/20121071olPbL2FRhv.png

Server Token 取得

  • 向 Server 節點添加 Agent 節點的安全認證就是需要它了!

Token 提取位置

  • 這邊的 Token 是不會因為重新啟動 Server 而改變的。
cat /var/lib/rancher/k3s/server/node-token

https://ithelp.ithome.com.tw/upload/images/20191002/20121071mzeMVODHKB.png

Token 重建方法

  • 用於之後 Agent 端點無法失敗或是叢集重建使後續重建 k3s server 重新生成 Token。
rm -r /var/lib/rancher/k3s
  • 刪除完之後~重新執行 Server 功能。

Agent 端

  • 一樣請用 root 進行操作

官方快速安裝版本

參考資料:https://github.com/rancher/k3s/blob/master/README.md

添加 Agent 節點

  • 這邊添加錯誤的 Token 仍然會執行,在 Server 端看不到節點即是失敗,需要多注意一下。
curl -sfL https://get.k3s.io | K3S_URL=https://myserver:6443 K3S_TOKEN=XXX sh -
  • 添加節點測試(示意圖)
    https://ithelp.ithome.com.tw/upload/images/20191002/20121071iOcdoq2Ene.png

Github Release 安裝版本

  • 這邊的方案類似於 kubernetes 的 kubeadm join 的架構去執行,但執行下去會在前景吐出接收派送指令與Agent端點的執行狀態。

添加 Agent 節點測試

k3s agent --server https://myserver:6443 --token ${NODE_TOKEN}

成功案例

  • 添加Agent節點測試(示意圖)
    https://ithelp.ithome.com.tw/upload/images/20191002/20121071LWUO4154pG.png

失敗案例 (Token 認證錯誤)

  • 添加Agent節點測試(示意圖)
    https://ithelp.ithome.com.tw/upload/images/20191002/20121071QsKBkYPuFE.png

背景執行 Agent

  • 背景執行添加Agent節點服務(示意圖)
    https://ithelp.ithome.com.tw/upload/images/20191002/20121071brhPn6CUzs.png

Agent 端 Token 異常

異常狀態

https://ithelp.ithome.com.tw/upload/images/20191002/201210718FaanDRRN8.png

刪除註冊資料

  • Server 與 Agent 停機之後,同步執行下面指令。
rm -rf /var/lib/rancher
  • 重建 Server --> 重新註冊 Agent

重新註冊 Server

https://ithelp.ithome.com.tw/upload/images/20191002/20121071Z92GR7viPo.png

叢集狀態鑑測

節點狀態檢測

k3s kubectl get node
  • 查看所有的可用節點(示意圖)
    https://ithelp.ithome.com.tw/upload/images/20191002/20121071843uZS0BTo.png

節點詳細資料

  • 所有節點詳細資訊
k3s kubectl describe node
  • 指定節點詳細資訊
k3s kubectl describe node ${Node-Name}

PC 端

  • 節點檢測示意圖
    https://ithelp.ithome.com.tw/upload/images/20191002/201210715KqLB4gXuQ.png

Raspberry Pi

  • 節點檢測示意圖
    https://ithelp.ithome.com.tw/upload/images/20191002/20121071KI6zeZlnSj.png

Raspberry Pi 的小天地

  • 應該有人發現上面的指令在 Raspberry Pi 上會錯誤吧(???)

維修一下出現的 Error Code

執行錯誤參考

  • cgroup 相關服務錯誤
    https://ithelp.ithome.com.tw/upload/images/20191002/20121071YGVl1EIdUD.png

熱血開修

  • 打開需修改的檔案
nano /boot/cmdline.txt
  • 添加下面的這行指令
cgroup_memory=1 cgroup_enable=memory
  • 確認修改後的文件
    https://ithelp.ithome.com.tw/upload/images/20191002/20121071fgSwwog7yV.png
  • 系統重新啟動 Raspberry Pi
init 6
  • 重新開機之後,再重新將 k3s 的服務啟動即可。

後面的文章將介紹一下 k3s 快速安裝的服務重建與卸載,並簡介 k3s 應用程式的基礎指令使用。


上一篇
[Day 15]K3s 安裝
下一篇
[Day 17]K3s 叢集重建與基礎指令簡介
系列文
從開源雲到邊緣運算30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言