zoukankan      html  css  js  c++  java
  • 边缘使用 K8s 门槛太高?OpenYurt 这个功能帮你快速搭建集群!

    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/openyurt
    https://docs.docker.com/engine/install/

  • 相关阅读:
    线程池的扩展 beforeExecute() afterExecute() terminaerd()
    信号量semaphore 读写锁ReadWriteLock 倒计时器CountDownLatch 循环栅栏 CyclicBarrier 线程阻塞工具类LockSupport
    ReenTrantLock可重入锁 和synchronized 内部所锁的
    integer.valueof和integer.parseint
    守护线程
    notify wait sleep join yield yield
    Thread.stop()不要随意调用
    iterate使用了parallel() 反而消耗了更多的时间
    Stream 分支/合并 框架的实际例子
    区分Collection、Collector和collect Collectors类的静态工厂方法
  • 原文地址:https://www.cnblogs.com/alisystemsoftware/p/15310048.html
Copyright © 2011-2022 走看看