OpenYurt是一个云边计端算平台,借助OpenYurt的能力,能够将现有的Kubernetes集群转换成OpenYurt集群,并将Kubernetes的能力延长到边缘侧。OpenYurt为云边端协同开发提供了多样化的性能,如买通云边通信的YurtTunnel,为了方便管理节点单元利用部署/运维的Yurt-App-Manager以及提供了边缘自治的YurtHub。

开发者能够专一于云边端产品上的利用开发而不必放心底层架构的运维。Shifu作为Kubernetes原生的开源物联网开发架构,能够兼容各种物联网设施的协定并将其形象成一个为微服务软件对象。二者的能力有十分好的互补性。尤其是在OpenYurt中退出了YurtDeviceController当前,Shifu能够用OpenYurt原生的形式来将设施进行形象,大大提高物联网开发者的开发效率。

应用OpenYurt和Shifu当前,咱们能够将本来简单的IoT,云边协同开发转化为简略的web式开发。

简介

本文是一个在OpenYurt集群中应用Shifu接入RTSP协定摄像头的指南,其中蕴含Shifu Framework, Docker, Linux, Kubernetes, OpenYurt的基本操作,任何开发者都能够浏览本文来学习Shifu Framework的开发方法。

本文中的Shifu Framework架构如下:

北向通过“deviceshifu-http-http”向上凋谢HTTP API接口,南向通过“rtsp-driver”来和理论设施交互

指标

  1. 在server和edge端通过 yurtctl 部署OpenYurt, 并将edge端退出server端的集群
  2. 在 edge 端部署网络摄像头的数字孪生
  3. 实现通过HTTP对网络摄像头的近程自动化管控

须要的设施

  1. 两台运行 Linux的虚拟机,server和edge的配置别离为 4核16G内存和2核8G内存
  2. 一个RTSP协定的网络摄像头,本文中用到的摄像头型号为海康威视的 “DS-2DE3Q140CN-W”

软件环境

-CentOS 7.9.2009

-Go v1.17.1

-yurtctl v0.6.1

-kubectl: v1.19.8

(installed by yurtctl)     

步骤

第一步:装置并部署OpenYurt集群

本文参考了OpenYurt的官网教程,地址为:
https://openyurt.io/docs/v0.6...

首先让咱们来下载OpenYurt,从官网的GitHub间接克隆我的项目:

git clone https://github.com/openyurtio/openyurt.git

接着让咱们下载v0.6.1版本的yurtctl

curl -LO https://github.com/openyurtio/openyurt/releases/download/v0.6.1/yurtctl chmod +x yurtctl
server端的部署:

在server端创立OpenYurt集群

./yurtctl init --apiserver-advertise-address <SERVER_IP> --openyurt-version latest --passwd 123 

看见如下信息即示意集群创立实现,这里的“--token”要记录一下用来将edge节点退出到集群中

接下来看一下各个Pod的运行状况,通过“kubectl get pods -A”:

遇到的几个问题

如果在“ kubectl logs yurt-hub-server -n kube-system”里遇到

请尝试“kubectl apply -f config/setup/yurt-controller-manager.yaml”

办法来自: https://github.com/openyurtio...

除此之外,还有几个问题,如在“kubectl logs yurt-hub-server -n kube-system”里遇到如下输入:

请尝试“kubectl apply -f config/setup/ yurthub-cfg.yaml”

如果在yurt-tunnel-server和yurt-tunnel-agent也遇到了相似的log,通过以下命令来修复yurt-tunnel的RBAC问题:

kubectl apply -f config/setup/yurt-tunnel-agent.yaml kubectl apply -f config/setup/yurt-tunnel-server.yaml

Untaint master节点来运行Shifu的controller:

kubectl taint nodes server node-role.kubernetes.io/master-

至此,Server端部署结束。

Edge 端的部署

首先利用方才server端init当前的token,执行:

./yurtctl join <MASTER_IP>:6443 --token <MASTER_INIT_TOKEN>  --node-type=edge --discovery-token-unsafe-skip-ca-verification --v=5 

确认Node状态,通过"kubectl get nodes”:

至此,一个server端+一个edge端的集群建设结束。

第二步:在集群中部署Shifu

接下来让咱们把Shifu部署到OpenYurt集群中
在server端,克隆Shifu我的项目到本地:

git clone https://github.com/Edgenesis/shifu.git cd shifu/

接下来,装置Shifu:

kubectl apply -f k8s/crd/install/shifu_install.yml

通过"kubectl get pods -A”查看Pod状态:

看到"shifu-crd-system” namespace中的Pod运行即可

至此,Shifu装置结束。

第三步:部署虚构摄像头 (camera deviceShifu)

OpenYurt提供了十分不便的节点池(NodePool)性能,能够让咱们治理节点集群,对集群进行部署。

创立”beijing”节点池:

export WORKER_NODEPOOL="beijing" export EDGE_NODE="edge" cat <<EOF | kubectl apply -f - apiVersion: apps.openyurt.io/v1alpha1 kind: NodePool metadata:   name: $WORKER_NODEPOOL spec:   type: Edge EOF

输入如下:

接着将edge服务器label到”beijing”的NodePool:

kubectl label node $EDGE_NODE apps.openyurt.io/desired-nodepool=beijing

查看一下NodePool的情况,应该有一个READYNODES:

kubectl get nodepool

因为物联网的边缘节点通常是分布式在同一场景内的,这里能够应用OpenYurt的UnitedDeployment性能依据NodePool来主动部署 。

装置 Yurt-app-manager

git clone https://github.com/openyurtio/yurt-app-manager.gitcd yurt-app-managerkubectl apply -f config/setup/all_in_one.yaml

应用用UnitedDeployment来部署虚构的海康摄像头,YAML文件如下:

apiVersion: apps.openyurt.io/v1alpha1kind: UnitedDeploymentmetadata:labels:  controller-tools.k8s.io: "1.0"name: deviceshifu-hikvision-camera-deploymentspec:selector:  matchLabels:    app: deviceshifu-hikvision-camera-deploymentworkloadTemplate:  deploymentTemplate:    metadata:      labels:        app: deviceshifu-hikvision-camera-deployment      name: deviceshifu-hikvision-camera-deployment      namespace: default    spec:      selector:        matchLabels:          app: deviceshifu-hikvision-camera-deployment      template:        metadata:          labels:            app: deviceshifu-hikvision-camera-deployment        spec:          containers:          - image: edgehub/deviceshifu-http-http:v0.0.1            name: deviceshifu-http            ports:            - containerPort: 8080            volumeMounts:            - name: deviceshifu-config              mountPath: "/etc/edgedevice/config"              readOnly: true            env:            - name: EDGEDEVICE_NAME              value: "deviceshifu-hikvision-camera"            - name: EDGEDEVICE_NAMESPACE              value: "devices"          - image: edgenesis/camera-python:v0.0.1            name: camera-python            ports:            - containerPort: 11112            volumeMounts:            - name: deviceshifu-config              mountPath: "/etc/edgedevice/config"              readOnly: true            env:            - name: EDGEDEVICE_NAME              value: "deviceshifu-hikvision-camera"            - name: EDGEDEVICE_NAMESPACE              value: "devices"            - name: IP_CAMERA_ADDRESS              value: "<CAMERA_IP>"            - name: IP_CAMERA_USERNAME              value: "<CAMERA_USERNAME>"            - name: IP_CAMERA_PASSWORD              value: "<CAMERA_PASSWORD>"            - name: IP_CAMERA_CONTAINER_PORT              value: "11112"            - name: PYTHONUNBUFFERED              value: "1"          volumes:          - name: deviceshifu-config            configMap:              name: deviceshifu-hikvision-camera-configmap-0.0.1          serviceAccountName: edgedevice-satopology:  pools:  - name: beijing    nodeSelectorTerm:      matchExpressions:      - key: apps.openyurt.io/nodepool        operator: In        values:        - beijing    replicas: 1revisionHistoryLimit: 5

Service文件:

apiVersion: v1kind: Servicemetadata:labels:  app: deviceshifu-hikvision-camera-deploymentname: deviceshifu-hikvision-cameranamespace: defaultspec:ports:- port: 80  protocol: TCP  targetPort: 8080selector:  app: deviceshifu-hikvision-camera-deploymenttype: LoadBalancer

edgeDevice文件:

apiVersion: shifu.edgenesis.io/v1alpha1kind: EdgeDevicemetadata:name: deviceshifu-hikvision-cameranamespace: devicesspec:sku: "HikVision Camera"connection: Ethernetaddress: 0.0.0.0:11112protocol: HTTP

ConfigMap文件:

apiVersion: v1kind: ConfigMapmetadata:name: deviceshifu-hikvision-camera-configmap-0.0.1namespace: defaultdata:driverProperties: |  driverSku: HikVision  driverImage: edgenesis/camera-python:v0.0.1instructions: |  capture:  info:  stream:  move/up:  move/down:  move/left:  move/right:telemetries: |  device_health:    properties:      instruction: info      initialDelayMs: 1000      intervalMs: 1000

将这四个文件放到一个目录,如下:

camera-unitedDeployment/ ├── camera-edgedevice.yaml ├── deviceshifu-camera-configmap.yaml ├── deviceshifu-camera-service.yaml └── deviceshifu-camera-unitedDeployment.yaml

接下来部署

kubectl apply -f camera-unitedDeployment/

通过“kubectl get ud”查看UnitedDeployment状态:

通过“kubectl get pods -owide”来确认Pod部署在了“beijing” NodePool里的edge服务器中:

咱们能够在集群中通过“kubectl get edgedevices -n devices”查看Shifu的虚构设施:

再通过“kubectl describe edgedevices -n devices” 查看设施的详细信息如配置,状态等:

至此,摄像头孪生部署结束。

最初一步:运行成果

接下来咱们来管制摄像头,这里应用一个nginx的pod来代表利用:

kubectl run nginx --image=nginx

待nginx开始运行时,通过“kubectl exec -it nginx -- bash”来进入nginx的命令行:

通过以下命令能够间接管制摄像头:

curl deviceshifu-hikvision-camera/move/{up/down/left/right}

如果咱们想查看摄像头以后拍摄以及以后视频流,须要将摄像头的service通过“kubectl port-forward service/deviceshifu-hikvision-camera 30080:80 --address='0.0.0.0'” 代理到本地。

在浏览器中输出服务器的IP加端口号,能够间接查看图像/视频流:

<SERVER_IP>:30080/capture<SERVER_IP>:30080/stream

总结

在此篇文章中,咱们讲述了如何将Shifu部署在OpenYurt集群中来减少RTSP摄像头的反对。

在未来的文章中,咱们也会尝试将Shifu与OpenYurt的yurt device controller进行整合,通过OpenYurt原生的形式延申OpenYurt的能力到更多物联网设施的治理中。

https://openyurt.io/zh/docs/c...

十分感谢您看到了这里,咱们期待您的反馈,如果感觉文章写得不错或者有任何倡议请毫不犹豫地留言。

本文由博客群发一文多发等经营工具平台 OpenWrite 公布