Author | Tang Bingchang
With the rapid development of edge computing, more and more data needs to be stored, processed, and analyzed at the edge of the network, leading to an explosive growth of edge devices and applications. Efficiently managing resources and applications at the edge is a major challenge faced by the industry. Currently, a cloud-native approach that integrates cloud computing capabilities into the edge and allows for unified scheduling and control in the cloud has gained widespread recognition in the industry.
As shown in Figure 1, this article demonstrates how to build a cloud management edge scenario by deploying a Kubernetes cluster control plane in the cloud and connecting a Raspberry Pi to the cluster. Based on this environment, we will showcase the core capabilities of OpenYurt and help you quickly get started with OpenYurt.
Environment Preparation
1. Basic Environment Introduction
2. Building a Native K8s Cluster
-
Install Kubernetes components on the cloud node and Raspberry Pi by executing the following commands.
curl -s https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | sudo apt-key add -echo "deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main" > /etc/apt/sources.list.d/kubernetes.listsudo apt-get updatesudo apt install -y kubelet=1.16.6-00 kubeadm=1.16.6-00 kubectl=1.16.6-00
-
Initialize the cloud node using kubeadm (execute the following command on the cloud node). During the deployment process, use Alibaba Cloud’s image repository. To support Raspberry Pi access, the images in this repository have a manifest list that can support both amd64 and arm64 CPU architectures.
# master-nodekubeadm init --image-repository=registry.cn-hangzhou.aliyuncs.com/edge-kubernetes --kubernetes-version=v1.16.6 --pod-network-cidr=10.244.0.0/16
mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
-
Connect the Raspberry Pi to the cloud cluster according to the node connection information output after initialization in step two, and execute the connection command on the Raspberry Pi.
kubeadm join 183.195.233.42:6443 --token XXXX
--discovery-token-ca-cert-hash XXXX
-
Add CNI configuration (both the cloud control node and Raspberry Pi need to be configured). The cluster built in this article uses the host network. Create the CNI configuration file /etc/cni/net.d/0-loopback.conf and copy the following content into this file.
{ "cniVersion": "0.3.0", "name": "lo", "type": "loopback"}
-
Check the deployment effect on the master node.
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIMEedge-node Ready <none> 74s v1.16.6 192.168.0.100 <none> Ubuntu 18.04.4 LTS 4.19.105-v8-28 docker://19.3.5master-node Ready master 2m5s v1.16.6 183.195.233.42 <none> Ubuntu 18.04.2 LTS 4.15.0-52-generic docker://19.3.5
-
Delete CoreDNS (CoreDNS is not needed in this demo) and remove the taints from the master node (to facilitate the subsequent deployment of OpenYurt components).
kubectl delete deployment coredns -n kube-systemkubectl taint node master-node node-role.kubernetes.io/master-
Issues with Native K8s Cluster in Edge Scenarios
Note: nodeSelector selects the edge-node node, the host network configuration is set to true, and the pod’s toleration time is configured to 5s (default is 5min, this configuration is for demonstration purposes to evict the pod quickly).
apiVersion: v1kind: Podmetadata: name: nginxspec: tolerations: - key: "node.kubernetes.io/unreachable" operator: "Exists" effect: "NoExecute" tolerationSeconds: 5 - key: "node.kubernetes.io/not-ready" operator: "Exists" effect: "NoExecute" tolerationSeconds: 5 nodeSelector: kubernetes.io/hostname: edge-node containers: - name: nginx image: nginx hostNetwork: true
root@master-node:~# kubectl get pods -owideNAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATESnginx 1/1 Running 0 11s 192.168.0.100 edge-node <none> <none>
1. Test common cluster operation commands, including logs, exec, port-forward.
root@master-node:~# kubectl logs nginxError from server: Get https://192.168.0.100:10250/containerLogs/default/nginx/nginx: dial tcp 192.168.0.100:10250: connect: connection refused
root@master-node:~# kubectl exec -it nginx shkubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl exec [POD] -- [COMMAND] instead.Error from server: error dialing backend: dial tcp 192.168.0.100:10250: connect: connection refused
root@master-node:~# kubectl port-forward pod/nginx 8888:80error: error upgrading connection: error dialing backend: dial tcp 192.168.0.100:10250: connect: connection refused
2. Test the impact on business during edge disconnection
-
Disconnect for 1 minute -> Restore network
-
Disconnect for 1 minute -> Restart edge node -> Restore network
1)Disconnect for 1 minute -> Restore network
root@master-node:~# kubectl get nodesNAME STATUS ROLES AGE VERSIONedge-node NotReady <none> 5m13s v1.16.6master-node Ready master 6m4s v1.16.6
root@master-node:~# kubectl get podsNAME READY STATUS RESTARTS AGEnginx 1/1 Terminating 0 3m45s
root@master-node:~# kubectl get podsNo resources found in default namespace.
root@master-node:~# kubectl get pods -owideNAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATESnginx 1/1 Running 0 4s 192.168.0.100 edge-node <none> <none>
2)Disconnect for 1 minute -> Restart edge node -> Restore network
root@edge-node:~# docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES9671cbf28ca6 e86f991e5d10 "/docker-entrypoint.…" About a minute ago Up About a minute k8s_nginx_nginx_default_efdf11c6-a41c-4b95-8ac8-45e02c9e1f4d_06272a46f93ef registry.cn-hangzhou.aliyuncs.com/edge-kubernetes/pause:3.1 "/pause" 2 minutes ago Up About a minute k8s_POD_nginx_default_efdf11c6-a41c-4b95-8ac8-45e02c9e1f4d_0698bb024c3db f9ea384ddb34 "/usr/local/bin/kube…" 8 minutes ago Up 8 minutes k8s_kube-proxy_kube-proxy-rjws7_kube-system_51576be4-2b6d-434d-b50b-b88e2d436fef_031952700c95b registry.cn-hangzhou.aliyuncs.com/edge-kubernetes/pause:3.1 "/pause" 8 minutes ago Up 8 minutes k8s_POD_kube-proxy-rjws7_kube-system_51576be4-2b6d-434d-b50b-b88e2d436fef_0
root@edge-node:~# docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES0c66b87066a0 473ae979be68 "yurt-tunnel-agent -…" 12 seconds ago Up 11 seconds k8s_yurt-tunnel-agent_yurt-tunnel-agent-7l8nv_kube-system_75d28494-f577-43fa-9cac-6681a1215498_2a4fb3e4e8c8f e86f991e5d10 "/docker-entrypoint.…" 58 seconds ago Up 56 seconds k8s_nginx_nginx_default_b45baaac-eebc-466b-9199-2ca5c1ede9fd_1fce730d64b32 f9ea384ddb34 "/usr/local/bin/kube…" 58 seconds ago Up 57 seconds k8s_kube-proxy_kube-proxy-rjws7_kube-system_51576be4-2b6d-434d-b50b-b88e2d436fef_2c78166ea563f registry.cn-hangzhou.aliyuncs.com/edge-kubernetes/pause:3.1 "/pause" 59 seconds ago Up 57 seconds k8s_POD_yurt-tunnel-agent-7l8nv_kube-system_75d28494-f577-43fa-9cac-6681a1215498_1799ad14bcd3b registry.cn-hangzhou.aliyuncs.com/edge-kubernetes/pause:3.1 "/pause" 59 seconds ago Up 57 seconds k8s_POD_nginx_default_b45baaac-eebc-466b-9199-2ca5c1ede9fd_1627673da6a85 registry.cn-hangzhou.aliyuncs.com/edge-kubernetes/pause:3.1 "/pause" 59 seconds ago Up 58 seconds k8s_POD_kube-proxy-rjws7_kube-system_51576be4-2b6d-434d-b50b-b88e2d436fef_204da705e4120 70bf6668c7eb "yurthub --v=2 --ser…" About a minute ago Up About a minute k8s_yurt-hub_yurt-hub-edge-node_kube-system_d75d122e752b90d436a71af44c0a53be_1260057d935ee registry.cn-hangzhou.aliyuncs.com/edge-kubernetes/pause:3.1 "/pause" About a minute ago Up About a minute k8s_POD_yurt-hub-edge-node_kube-system_d75d122e752b90d436a71af44c0a53be_1
root@master-node:~# kubectl get pods -owideNAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATESnginx 1/1 Running 1 11m 192.168.0.100 edge-node <none> <none>
yurtctl revert --yurtctl-servant-image=registry.cn-hangzhou.aliyuncs.com/openyurt/yurtctl-servant:v0.2.1
We welcome everyone to participate in the co-construction of this project. If you have any questions, you can scan the QR code to join the group for communication.
