云原生管理端设备

本文档主要讲述如何在已有的OpenYurt集群上安装Yurt-Device-Controller 和 Yurt-EdgeX-Manager组件,并通过部署虚拟端设备来展示如何通过云原生的方式管理边缘端设备。

对于有兴趣的读者,可以去相关的github仓库参考本文使用组件的具体实现:Yurt-Device-ControllerYurt-EdgeX-Manager

如果你还没有OpenYurt集群,你可以使用 yurtctl工具 来初始化一个OpenYurt集群或将一个Kubernetes集群转换为OpenYurt集群。

环境要求

  • OpenYurt v0.5.0+

  • 安装了 Yurt-app-manager 组件

  • 与master不在同一局域网下的节点都需要部署coreDNS pod

  • 将访问coreDNS service的流量改为节点池内闭环,参考教程

1. 安装yurt-edgex-manager并创建一个EdgeX实例

安装部署yurt-edgex-manager

  1. $ kubectl apply -f https://github.com/openyurtio/yurt-edgex-manager/releases/download/v0.2.0/yurt-edgex-manager.yaml
  2. # 检查状态
  3. $ kubectl get pods -n edgex-system |grep edgex
  4. edgex-controller-manager-6c99fd9f9f-b9nnk 2/2 Running 0 6d22h

创建一个hangzhou边缘节点池,并将边缘节点加入到hangzhou节点池

  1. $ export WORKER_NODEPOOL="hangzhou"
  2. $ export EDGE_NODE="node1"
  3. # 创建hangzhou节点池
  4. $ cat <<EOF | kubectl apply -f -
  5. apiVersion: apps.openyurt.io/v1alpha1
  6. kind: NodePool
  7. metadata:
  8. name: $WORKER_NODEPOOL
  9. spec:
  10. type: Edge
  11. EOF
  12. # 将边缘节点加入hangzhou节点池
  13. $ kubectl label node $EDGE_NODE apps.openyurt.io/desired-nodepool=hangzhou
  14. # 检查节点池状态
  15. $ kubectl get nodepool
  16. NAME TYPE READYNODES NOTREADYNODES AGE
  17. hangzhou Edge 0 1 6d22h

在hangzhou节点池中创建edgex foundry实例,并在edgex中部署虚拟设备edgex-device-virtual

  1. apiVersion: device.openyurt.io/v1alpha1
  2. kind: EdgeX
  3. metadata:
  4. name: edgex-sample-beijing
  5. spec:
  6. version: jakarta
  7. poolname: hangzhou
  8. ---
  9. apiVersion: apps/v1
  10. kind: Deployment
  11. metadata:
  12. labels:
  13. org.edgexfoundry.service: edgex-device-virtual
  14. name: edgex-device-virtual
  15. spec:
  16. replicas: 1
  17. selector:
  18. matchLabels:
  19. org.edgexfoundry.service: edgex-device-virtual
  20. strategy:
  21. type: Recreate
  22. template:
  23. metadata:
  24. labels:
  25. org.edgexfoundry.service: edgex-device-virtual
  26. spec:
  27. hostname: edgex-device-virtual
  28. nodeSelector:
  29. apps.openyurt.io/nodepool: hangzhou
  30. containers:
  31. - name: edgex-device-virtual
  32. image: openyurt/device-virtual:2.1.0
  33. imagePullPolicy: IfNotPresent
  34. ports:
  35. - containerPort: 59900
  36. name: "tcp-59900"
  37. protocol: TCP
  38. env:
  39. - name: MESSAGEQUEUE_HOST
  40. value: edgex-redis
  41. - name: SERVICE_HOST
  42. value: edgex-device-virtual
  43. envFrom:
  44. - configMapRef:
  45. name: common-variables
  46. startupProbe:
  47. tcpSocket:
  48. port: 59900
  49. periodSeconds: 1
  50. failureThreshold: 120
  51. livenessProbe:
  52. tcpSocket:
  53. port: 59900
  54. restartPolicy: Always
  55. ---
  56. apiVersion: v1
  57. kind: Service
  58. metadata:
  59. labels:
  60. org.edgexfoundry.service: edgex-device-virtual
  61. name: edgex-device-virtual
  62. spec:
  63. ports:
  64. - name: "tcp-59900"
  65. port: 59900
  66. protocol: TCP
  67. targetPort: 59900
  68. selector:
  69. org.edgexfoundry.service: edgex-device-virtual
  70. type: NodePort

检查edgex-foundry的部署状态

  1. $ kubectl get edgex
  2. NAME READY SERVICE READYSERVICE DEPLOYMENT READYDEPLOYMENT
  3. edgex-sample-hangzhou true 9 9 9 9

2. 安装并部署yurt-device-controller

安装yurt-device-controller 相关的CRD

  1. $ kubectl apply -f https://raw.githubusercontent.com/openyurtio/yurt-device-controller/main/config/setup/crd.yaml

使用UnitedDeployment在hanghzou节点池中部署一个yurt-device-controller实例

  1. apiVersion: apps.openyurt.io/v1alpha1
  2. kind: UnitedDeployment
  3. metadata:
  4. labels:
  5. controller-tools.k8s.io: "1.0"
  6. name: ud-device
  7. namespace: default
  8. spec:
  9. selector:
  10. matchLabels:
  11. app: ud-device
  12. topology:
  13. pools:
  14. - name: hangzhou
  15. nodeSelectorTerm:
  16. matchExpressions:
  17. - key: apps.openyurt.io/nodepool
  18. operator: In
  19. values:
  20. - hangzhou
  21. replicas: 1
  22. tolerations:
  23. - operator: Exists
  24. workloadTemplate:
  25. deploymentTemplate:
  26. metadata:
  27. creationTimestamp: null
  28. labels:
  29. app: ud-device
  30. spec:
  31. selector:
  32. matchLabels:
  33. app: ud-device
  34. strategy: {}
  35. template:
  36. metadata:
  37. creationTimestamp: null
  38. labels:
  39. app: ud-device
  40. control-plane: controller-manager
  41. spec:
  42. containers:
  43. - args:
  44. - --health-probe-bind-address=:8081
  45. - --metrics-bind-address=127.0.0.1:8080
  46. - --leader-elect=false
  47. - --namespace=default
  48. - --v=5
  49. command:
  50. - /yurt-device-controller
  51. image: openyurt/yurt-device-controller:v0.2.0
  52. imagePullPolicy: IfNotPresent
  53. livenessProbe:
  54. failureThreshold: 3
  55. httpGet:
  56. path: /healthz
  57. port: 8081
  58. scheme: HTTP
  59. initialDelaySeconds: 15
  60. periodSeconds: 20
  61. successThreshold: 1
  62. timeoutSeconds: 1
  63. name: manager
  64. readinessProbe:
  65. failureThreshold: 3
  66. httpGet:
  67. path: /readyz
  68. port: 8081
  69. scheme: HTTP
  70. initialDelaySeconds: 5
  71. periodSeconds: 10
  72. successThreshold: 1
  73. timeoutSeconds: 1
  74. resources:
  75. limits:
  76. cpu: 100m
  77. memory: 512Mi
  78. requests:
  79. cpu: 100m
  80. memory: 512Mi
  81. securityContext:
  82. allowPrivilegeEscalation: false
  83. dnsPolicy: ClusterFirst
  84. restartPolicy: Always
  85. securityContext:
  86. runAsUser: 65532
  87. ---
  88. apiVersion: rbac.authorization.k8s.io/v1
  89. kind: ClusterRoleBinding
  90. metadata:
  91. name: ud-rolebinding
  92. roleRef:
  93. apiGroup: rbac.authorization.k8s.io
  94. kind: ClusterRole
  95. name: cluster-admin
  96. subjects:
  97. - kind: ServiceAccount
  98. name: default
  99. namespace: default

检查yurt-device-controller是否部署成功

  1. $ kubectl get pod |grep yurt-device-controller
  2. yurt-device-controller-beijing-sf7xz-79c9cbf4b7-mbfds 1/1 Running 0 6d22h

3. 查看同步上来设备相关信息

上文中提到的device-virtual-go驱动会自动往EdgeX实例中注册5个虚拟设备,yurt-device-controller会将它自动同步上来

  1. $ kubectl get device
  2. NAME NODEPOOL SYNCED AGE
  3. hangzhou-random-binary-device hangzhou true 19h
  4. hangzhou-random-boolean-device hangzhou true 19h
  5. hangzhou-random-float-device hangzhou true 19h
  6. hangzhou-random-integer-device hangzhou true 19h
  7. hangzhou-random-unsignedinteger-device hangzhou true 19h

4. 卸载相关组件并清理环境

  1. $ export WORKER_NODEPOOL="hangzhou"
  2. $ export EDGE_NODE="node1"
  3. # 1.1 删除所有device, deviceservice, deviceprofile资源
  4. $ kubectl delete device --all
  5. $ kubectl delete deviceprofile --all
  6. $ kubectl delete deviceservice --all
  7. # 1.2 删除部署的yurt-device-controller
  8. $ kubectl delete uniteddeployment yurt-device-controller
  9. $ kubectl delete clusterrolebinding ud-rolebinding
  10. # 1.3 删除device, deviceservice, deviceprofile资源相关的crd
  11. $ kubectl delete -f https://raw.githubusercontent.com/openyurtio/yurt-device-controller/main/config/setup/crd.yaml
  12. # 2.1 删除所有edgex实例
  13. $ kubectl delete edgex --all
  14. # 2.2 卸载yurt-edgex-manager
  15. $ kubectl delete -f https://github.com/openyurtio/yurt-edgex-manager/releases/download/v0.2.0/yurt-edgex-manager.yaml
  16. # (以下步骤可选)
  17. # 3.1 将边缘节点移除hangzhou节点池
  18. $ kubectl label node $EDGE_NODE apps.openyurt.io/desired-nodepool-
  19. # 3.2 删除hangzhou节点池
  20. $ kubectl delete nodepool $WORKER_NODEPOOL