边缘使用 K8s 门槛太高?OpenYurt 这个功能帮你快速搭建集群!
OpenYurt 作为阿里巴巴首个开源的边缘云原生项目,涉及到边缘计算和云原生两个领域。然而,许多边缘计算的开发者并不熟悉云原生相关的知识。为了降低 OpenYurt 的使用门槛,帮助更多地开发者快速上手 OpenYurt,社区提供了 OpenYurt 易用性工具 yurtctl。该工具致力于屏蔽 OpenYurt 集群创建的复杂性,帮助开发者在本地快速地搭建 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
环境准备
(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
_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"}
2
一键拉起控制面节点
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
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
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
root@master:~# kubectl get nodes
NAME STATUS ROLES AGE VERSION
master Ready <none> 50s v1.18.8
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
配合实现从云到边的运维能力。
3
一键接入云端节点
root@cloud-node:~#./yurtctl join 111.32.157.130:6443 --token vowclg.k7059m0f0qbcebpg --discovery-token-ca-cert-hash sha256:30846295ea024260bc3c4988507c4408e8756ca5440221e109fe8167f636f125 --node-type=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.
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
4
一键接入边缘节点
root@edge-node:~# ./yurtctl join 111.32.157.130:6443 --token vowclg.k7059m0f0qbcebpg --discovery-token-ca-cert-hash sha256:30846295ea024260bc3c4988507c4408e8756ca5440221e109fe8167f636f125 --node-type=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.
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
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-hub
与kube-apiserver
交互。当云边网络良好时,yurt-hub
转发节点组件的请求到kube-apiserver
,并缓存 Response 内容。当云边断网时,edge-hub
从本地缓存中获取数据响应边缘节点组件的请求。 -
yurt-tunnel-agent
云边运维通道客户端,与yurt-tunnel-server
配合,实现从云到边的运维。
./yurtctl reset
。
5
沟通与交流
如果您对于 OpenYurt 有任何疑问,欢迎使用钉钉扫描二维码或者搜索群号(31993519)加入钉钉交流群。
相关链接:
https://github.com/openyurtio/openyurt
https://docs.docker.com/engine/install/