EdgeX Foundry

本文档主要讲述如何在已有的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. # 如果期望部署edgex的节点是arm64架构,则使用以下的yaml文件
  2. # kubectl apply -f https://raw.githubusercontent.com/openyurtio/yurt-edgex-manager/main/Documentation/yurt-edgex-manager-arm64.yaml
  3. $ kubectl apply -f https://raw.githubusercontent.com/openyurtio/yurt-edgex-manager/main/Documentation/yurt-edgex-manager.yaml
  4. # 检查状态
  5. $ kubectl get pods -n edgex-system |grep edgex
  6. 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. $ export WORKER_NODEPOOL="hangzhou"
  2. # 如果部署节点是arm64,则改为"edgexfoundry/docker-device-virtual-go-arm64:1.3.0"
  3. $ export VIRTUAL_DEVICE_IMAGE="edgexfoundry/docker-device-virtual-go:1.3.0"
  4. $ cat <<EOF | kubectl apply -f -
  5. apiVersion: device.openyurt.io/v1alpha1
  6. kind: EdgeX
  7. metadata:
  8. name: edgex-sample-$WORKER_NODEPOOL
  9. spec:
  10. version: hanoi
  11. poolname: $WORKER_NODEPOOL
  12. additinalservices:
  13. - metadata:
  14. name: edgex-device-virtual
  15. spec:
  16. type: NodePort
  17. selector:
  18. app: edgex-device-virtual
  19. ports:
  20. - name: http
  21. port: 49990
  22. protocol: TCP
  23. targetPort: 49990
  24. nodePort: 30090
  25. additinaldeployments:
  26. - metadata:
  27. name: edgex-device-virtual
  28. spec:
  29. selector:
  30. matchLabels:
  31. app: edgex-device-virtual
  32. template:
  33. metadata:
  34. labels:
  35. app: edgex-device-virtual
  36. spec:
  37. hostname: edgex-device-virtual
  38. containers:
  39. - name: edgex-device-virtual
  40. image: $VIRTUAL_DEVICE_IMAGE
  41. imagePullPolicy: IfNotPresent
  42. ports:
  43. - name: http
  44. protocol: TCP
  45. containerPort: 49990
  46. envFrom:
  47. - configMapRef:
  48. name: common-variables
  49. env:
  50. - name: Service_Host
  51. value: "edgex-device-virtual"
  52. EOF

检查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. $ export WORKER_NODEPOOL="hangzhou"
  2. $ cat <<EOF | kubectl apply -f -
  3. apiVersion: apps.openyurt.io/v1alpha1
  4. kind: UnitedDeployment
  5. metadata:
  6. labels:
  7. controller-tools.k8s.io: "1.0"
  8. name: yurt-device-controller
  9. spec:
  10. selector:
  11. matchLabels:
  12. app: yurt-device-controller
  13. workloadTemplate:
  14. deploymentTemplate:
  15. metadata:
  16. labels:
  17. app: yurt-device-controller
  18. spec:
  19. template:
  20. metadata:
  21. labels:
  22. app: yurt-device-controller
  23. control-plane: controller-manager
  24. spec:
  25. containers:
  26. - args:
  27. - --health-probe-bind-address=:8081
  28. - --metrics-bind-address=127.0.0.1:8080
  29. - --leader-elect=false
  30. command:
  31. - /yurt-device-controller
  32. image: openyurt/yurt-device-controller:latest
  33. imagePullPolicy: IfNotPresent
  34. livenessProbe:
  35. httpGet:
  36. path: /healthz
  37. port: 8081
  38. initialDelaySeconds: 15
  39. periodSeconds: 20
  40. name: manager
  41. readinessProbe:
  42. httpGet:
  43. path: /readyz
  44. port: 8081
  45. initialDelaySeconds: 5
  46. periodSeconds: 10
  47. resources:
  48. limits:
  49. cpu: 100m
  50. memory: 30Mi
  51. requests:
  52. cpu: 100m
  53. memory: 20Mi
  54. securityContext:
  55. allowPrivilegeEscalation: false
  56. securityContext:
  57. runAsUser: 65532
  58. terminationGracePeriodSeconds: 10
  59. topology:
  60. pools:
  61. - name: $WORKER_NODEPOOL
  62. nodeSelectorTerm:
  63. matchExpressions:
  64. - key: apps.openyurt.io/nodepool
  65. operator: In
  66. values:
  67. - $WORKER_NODEPOOL
  68. replicas: 1
  69. tolerations:
  70. - effect: NoSchedule
  71. key: apps.openyurt.io/example
  72. operator: Exists
  73. revisionHistoryLimit: 5
  74. ---
  75. kind: ClusterRoleBinding
  76. apiVersion: rbac.authorization.k8s.io/v1
  77. metadata:
  78. name: default-cluster-admin
  79. subjects:
  80. - kind: ServiceAccount
  81. name: default
  82. namespace: default
  83. roleRef:
  84. kind: ClusterRole
  85. name: cluster-admin
  86. apiGroup: ""
  87. ---
  88. EOF

检查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. 查看同步上来设备相关信息

可以通过以下命令查看同步上来设备相关信息

  1. $ kubectl get device
  2. $ kubectl get deviceservice
  3. $ kubectl get deviceprofile

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 default-cluster-admin
  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. # 如果使用的arm64版本的,使用以下命令
  16. # kubectl delete -f https://raw.githubusercontent.com/openyurtio/yurt-edgex-manager/main/Documentation/yurt-edgex-manager-arm64.yaml
  17. $ kubectl delete -f https://raw.githubusercontent.com/openyurtio/yurt-edgex-manager/main/Documentation/yurt-edgex-manager.yaml
  18. # (以下步骤可选)
  19. # 3.1 将边缘节点移除hangzhou节点池
  20. $ kubectl label node $EDGE_NODE apps.openyurt.io/desired-nodepool-
  21. # 3.2 删除hangzhou节点池
  22. $ kubectl delete nodepool $WORKER_NODEPOOL