天天看點

邊緣使用 K8s 門檻太高?OpenYurt 這個功能幫你快速搭建叢集!環境準備一鍵拉起控制面節點一鍵接入雲端節點一鍵接入邊緣節點

簡介: 為了降低 OpenYurt 的使用門檻,幫助更多地開發者快速上手 OpenYurt,社群提供了 OpenYurt 易用性工具 yurtctl。該工具緻力于屏蔽 OpenYurt 叢集建立的複雜性,幫助開發者在本地快速地搭建 OpenYurt 開發測試叢集。

OpenYurt 作為阿裡巴巴首個開源的邊緣雲原生項目,涉及到邊緣計算和雲原生兩個領域。然而,許多邊緣計算的開發者并不熟悉雲原生相關的知識。為了降低 OpenYurt 的使用門檻,幫助更多地開發者快速上手 OpenYurt,社群提供了 OpenYurt 易用性工具 yurtctl。該工具緻力于屏蔽 OpenYurt  叢集建立的複雜性,幫助開發者在本地快速地搭建 OpenYurt 開發測試叢集。

OpenYurt 采用雲管邊的架構,在原生 Kubernetes 叢集之上,以 Addon 的形式進行功能增強,解決了雲管邊場景中,雲邊網絡不穩定、雲邊運維難等關鍵問題,并實作了工作負載/流量的單元化管理、邊緣本地存儲、物聯網裝置管理等核心功能。本文實驗的拓撲如圖所示:

邊緣使用 K8s 門檻太高?OpenYurt 這個功能幫你快速搭建叢集!環境準備一鍵拉起控制面節點一鍵接入雲端節點一鍵接入邊緣節點

其中,藍色部分是原生的 k8s 元件,橙色部分是 OpenYurt 提供的元件。

  • Master 節點位于雲端,作為 OpenYurt 叢集的管控節點,同時也作為叢集的 Cloud Node,上面部署了原生 k8s 的控制面元件 controlplane,以及 OpenYurt 的管控元件 yurt-controller-manager、yurt-app-manager、yurt-tunnel-server
  • Cloud-Node 節點位于雲端,作為 OpenYurt 叢集的 Cloud Node,可以用于部署 OpenYurt 的管控元件,本文實驗中隻用于示範了雲端節點接入操作,沒有實際部署OpenYurt的管控元件。
  • Edge-Node 位于邊緣,作為叢集的邊緣節點,部署了節點自治元件 YurtHub,以及雲端通道元件 tunnel-agent。

環境準備

(1)三台 Linux 作業系統的計算機。一個作為控制平面節點(同時也是雲端節點)、一個作為雲端節點和一個作為邊緣節點,系統均為 Ubuntu18.04)。

(2)系統預安裝 Docker,安裝方式參考。

(3)關閉系統交換分區,不同版本系統的關閉方式存在差異,本文環境執行 swapoff -a 關閉。

(4)下載下傳 OpenYurt 社群代碼,建構 yurtctl 工具,并将 yurtctl 拷貝到三台主機上。

git clone https://github.com/openyurtio/openyurt.git
cd openyurt
export GOOS=linux GOARCH=amd64; make build  WHAT=cmd/yurtctl
      

建構的 yurtctl 在目錄

_output/bin/

中,其中本文采用的 yurtctl 版本為:

[email protected]:~# ./yurtctl --version
yurtctl version: projectinfo.Info{GitVersion:"v0.4.1", GitCommit:"3315ccc", BuildDate:"2021-09-08T02:48:34Z", GoVersion:"go1.13", Compiler:"gc", Platform:"linux/amd64"}
      

一鍵拉起控制面節點

在 yurtctl 中,提供了init子指令用于拉起 OpenYurt 的管控節點。該節點中部署了 Kubernetes 叢集的管控元件(kube-apiserver/kube-scheduler/kube-controller-manager/etcd)。同時也作為 OpenYurt 雲端管控節點部署了 OpenYurt 的管控元件(yurt-controller-manager/yurt-app-manager/yurt-tunnel-server)

在控制面節點上,執行如下指令

[email protected]:~# ./yurtctl init --image-repository=registry.cn-hangzhou.aliyuncs.com/google_containers --kubernetes-version=v1.18.8  --pod-network-cidr=10.244.0.0/16
      

該指令指定了 Kubernetes 相關元件的鏡像倉庫為 registry.cn-hangzhou.aliyuncs.com/google_containers,此外指定的 Kubernetes 叢集的版本為1.18.8(推薦)。yurtctl init 指令的更多參數可以參考

yurtctl init --help

.

yurtctl init

指令執行成功之後會同步輸出添加雲端節點和邊緣節點的指令。

Your OpenYurt cluster control-plane has initialized successfully!
        To start using your cluster, you need to run the following as a regular user:
          mkdir -p $HOME/.kube
          sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
          sudo chown $(id -u):$(id -g) $HOME/.kube/config
        Then you can join any number of edge-nodes by running the following on each as root:
        yurtctl join 111.32.157.130:6443 --token tfdxae.lvmb7orduikbyjqu \
    --discovery-token-ca-cert-hash sha256:0e1faf696fe976a7b28c03e0dece429c85d72e6e1e6bc2dd1ac3d30d0416f3f0  --node-type=edge-node
        And you can join any number of cloud-nodes by running the following on each as root:
        yurtctl join 111.32.157.130:6443 --token tfdxae.lvmb7orduikbyjqu \
    --discovery-token-ca-cert-hash sha256:0e1faf696fe976a7b28c03e0dece429c85d72e6e1e6bc2dd1ac3d30d0416f3f0  --node-type=cloud-node
      

根據提示,執行如下指令,拷貝證書到相應的目錄,就可以使用 kubectl 操作叢集

mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
      

在 master 節點上,檢視 master 節點的狀态

[email protected]:~# kubectl get nodes
NAME     STATUS   ROLES    AGE   VERSION
master   Ready    <none>   50s   v1.18.8
      

檢視 master 節點元件是否 Runnin

[email protected]:~# kubectl get pods -A
NAMESPACE     NAME                                       READY   STATUS    RESTARTS   AGE
kube-system   controlplane-master                        4/4     Running   0          55s
kube-system   coredns-546565776c-88hs6                   1/1     Running   0          46s
kube-system   coredns-546565776c-v5wxb                   1/1     Running   0          46s
kube-system   kube-flannel-ds-h6qqc                      1/1     Running   0          45s
kube-system   kube-proxy-6rnq2                           1/1     Running   0          45s
kube-system   yurt-app-manager-75b7f76546-6dsw9          1/1     Running   0          45s
kube-system   yurt-app-manager-75b7f76546-x6wzm          1/1     Running   0          45s
kube-system   yurt-controller-manager-697877d548-kd5xf   1/1     Running   0          46s
kube-system   yurt-tunnel-server-bc5cb5bf-xxqgj          1/1     Running   0          46s
      

其中,各個元件的功能如下:

  • controlplane

    為 all-in-one 的 Kubernetes 管控元件,為了便于了解 OpenYurt 與 Kubernetes 的關系,

    yurtctl init

    将 Kubernetes 的管控元件以黑盒的形式部署在同一個 Pod 中。
  • yurt-app-manager

    為 OpenYurt 的單元化元件,提供 workload 的單元化部署、運維等能力;
  • yurt-controller-manager

    為節點生命周期管理元件,與邊緣節點上的 yurt-hub 配合實作邊緣節點的自治功能;
  • yurt-tunnel-server

    為雲邊運維通道的 server 端,與邊緣節點上的

    yurt-tunnel-agent

    配合實作從雲到邊的運維能力。

一鍵接入雲端節點

雲端節點用來部署 OpenYurt 相關的系統元件。在 yurtctl 中,提供了 join 子指令,用于向 OpenYurt 叢集中增加雲端節點。此外,在用 yurtctl init 初始化 master 節點時,會将 master 節點也作為一個雲端節點使用。如果需要增加新的雲端節點,可以使用 init 的輸出,拷貝雲端節點接入指令到需要添加的雲端節點上執行。

[email protected]:~#./yurtctl join 111.32.157.130:6443 --token vowclg.k7059m0f0qbcebpg --discovery-token-ca-cert-hash sha256:30846295ea024260bc3c4988507c4408e8756ca5440221e109fe8167f636f125 --node-type=cloud-node
      

接入指令中指定了 master 節點的位址,以及接入認證需要的 token 和要接入的節點類型(cloud-node),執行成功輸出如下

This node has joined the cluster:
* Certificate signing request was sent to apiserver and a response was received.
* The Kubelet was informed of the new secure connection details.
Run 'kubectl get nodes' on the control-plane to see this node join the cluster.
      

在 master 節點上檢視剛接入的雲端節點狀态是否 Ready

[email protected]:~# kubectl get nodes -l openyurt.io/is-edge-worker=false
NAME         STATUS   ROLES    AGE     VERSION
cloud-node   Ready    <none>   5m4s    v1.18.8
master       Ready    <none>   9m40s   v1.18.8
      

一鍵接入邊緣節點

邊緣節點作為 OpenYurt 叢集實際部署業務的節點,通常部署在使用者的内網環境,與管控元件的網絡連接配接通常不穩定。是以,邊緣節點上需要部署節點自治元件 yurt-hub 以及雲邊運維元件 yurt-tunnel-agent。在 yurtctl 中,提供了 join 子指令,用于向 OpenYurt 叢集中添加邊緣節點。使用 init 中的輸出指令,拷貝邊緣節點接入指令到需要添加的邊緣節點上執行。

[email protected]:~# ./yurtctl join 111.32.157.130:6443 --token vowclg.k7059m0f0qbcebpg --discovery-token-ca-cert-hash sha256:30846295ea024260bc3c4988507c4408e8756ca5440221e109fe8167f636f125  --node-type=edge-node
      

接入指令中指定了 master 節點的位址,以及接入認證需要的 token 和要接入的節點類型(edge-node),執行成功輸出如下

This node has joined the cluster:
* Certificate signing request was sent to apiserver and a response was received.
* The Kubelet was informed of the new secure connection details.
Run 'kubectl get nodes' on the control-plane to see this node join the cluster.
      

在master節點上檢視剛接入的邊緣節點狀态是否Ready

[email protected]:~# kubectl get nodes -l openyurt.io/is-edge-worker=true
NAME        STATUS   ROLES    AGE   VERSION
edge-node   Ready    <none>   26s   v1.18.8
      

檢視邊緣節點的元件是否 Running

[email protected]:~# kubectl get pods -A -o wide | grep edge-node
kube-system   kube-flannel-ds-tdqtx                      1/1     Running   0          58s   103.15.99.183    edge-node    <none>           <none>
kube-system   kube-proxy-8r76s                           1/1     Running   0          58s   103.15.99.183    edge-node    <none>           <none>
kube-system   yurt-hub-edge-node                         1/1     Running   0          16s   103.15.99.183    edge-node    <none>           <none>
kube-system   yurt-tunnel-agent-v4jwt                    1/1     Running   0          38s   103.15.99.183    edge-node    <none>           <none>
      

其中,各個邊緣節點上各個元件功能如下:

  • yurt-hub

    邊緣節點自治元件,邊緣節點上的元件通過

    yurt-hub

    kube-apiserver

    互動。當雲邊網絡良好時,

    yurt-hub

    轉發節點元件的請求到

    kube-apiserver

    ,并緩存 Response 内容。當雲邊斷網時,

    edge-hub

    從本地緩存中擷取資料響應邊緣節點元件的請求。
  • yurt-tunnel-agent

    雲邊運維通道用戶端,與

    yurt-tunnel-server

    配合,實作從雲到邊的運維。

經過以上4個步驟,您就可以在本地擁有一套 OpenYurt 叢集。如果需要清理 OpenYurt 叢集,可以在叢集中的每個節點上執行

./yurtctl reset

OpenYurt 背靠原生的 Kubernetes,同時又面向邊緣計算場景。由于 Kubernetes 本身的複雜性,導緻很多非原生領域的同學難以上手使用。而 OpenYurt 叢集的搭建作為上手的第一步,阻擋了大部分的邊緣計算玩家。為了提升 OpenYurt 的易用性,yurtctl 設計了 init、join、reset、convert 等工具,目的在于幫助使用者快速地在本地搭建 OpenYurt 叢集,跨越使用 OpenYurt 的第一步。雖然目前易用性有了很大的提升,但是仍然有很多不足之處。期待社群的同學積極參與,基于 OpenYurt,一起打造更加易用的邊緣雲原生基礎設施。

原文連結

本文為阿裡雲原創内容,未經允許不得轉載。