边缘使用 K8s 门槛太高?OpenYurt 这个功能帮你快速搭建集群!

网友投稿 280 2022-11-06

边缘使用 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 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 5m4s v1.18.8 master Ready 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 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 kube-system kube-proxy-8r76s 1/1 Running 0 58s 103.15.99.183 edge-node kube-system yurt-hub-edge-node 1/1 Running 0 16s 103.15.99.183 edge-node kube-system yurt-tunnel-agent-v4jwt 1/1 Running 0 38s 103.15.99.183 edge-node

其中,各个边缘节点上各个组件功能如下:

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:基于Spartan3 XCS1000实现NGN网关接口芯片的设计
下一篇:Spring的DI依赖注入详解
相关文章

 发表评论

暂时没有评论,来抢沙发吧~