关于云原生:边缘使用-K8s-门槛太高OpenYurt-这个功能帮你快速搭建集群

5次阅读

共计 6415 个字符,预计需要花费 17 分钟才能阅读完成。

OpenYurt 作为阿里巴巴首个开源的边缘云原生我的项目,波及到边缘计算和云原生两个畛域。然而,许多边缘计算的开发者并不相熟云原生相干的常识。为了升高 OpenYurt 的应用门槛,帮忙更多地开发者疾速上手 OpenYurt,社区提供了 OpenYurt 易用性工具 yurtctl。该工具致力于屏蔽 OpenYurt 集群创立的复杂性,帮忙开发者在本地疾速地搭建 OpenYurt 开发测试集群。

OpenYurt 采纳云管边的架构,在原生 Kubernetes 集群之上,以 Addon 的模式进行性能加强,解决了云管边场景中,云边网络不稳固、云边运维难等关键问题,并实现了工作负载 / 流量的单元化治理、边缘本地存储、物联网设施治理等外围性能。本文试验的拓扑如图所示:

其中,蓝色局部是原生的 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 版本为:

root@master:~# ./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)

在管制面节点上,执行如下命令

root@master:~# ./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 节点的状态

root@master:~# kubectl get nodes
NAME     STATUS   ROLES    AGE   VERSION
master   Ready    <none>   50s   v1.18.8

查看 master 节点组件是否 Running

root@master:~# 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 的输入,拷贝云端节点接入指令到须要增加的云端节点上执行。

root@cloud-node:~#./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

root@master:~# 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 中的输入命令,拷贝边缘节点接入指令到须要增加的边缘节点上执行。

root@edge-node:~# ./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

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

查看边缘节点的组件是否 Running

root@master:~# 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-hubkube-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,一起打造更加易用的边缘云原生基础设施。

沟通与交换

如果您对于 OpenYurt 有任何疑难,欢送应用钉钉扫描二维码或者搜寻群号(31993519)退出钉钉交换群。

相干链接:
https://github.com/openyurtio…
https://docs.docker.com/engin…

正文完
 0