Device CRDs

KubeEdge supports device management with the help of Kubernetes CRDs and Device Mapper corresponding to the device being used. We currently use Device Model and Device Instance to define the device.

Notice

Device CRDs are updated from v1alpha2 to v1beta1 in release v1.15. It is not compatible with v1alpha1 and v1alpha2. Details can be found device-crd-v1beta1.

Device Model

A device model describes the device properties exposed by a type of devices. A device model is a Physical model which constrains the properties and parameters of physical devices.

Device Model Sample

A sample device model like below. For complete Device Model definition, you can refer to device-model.

  1. apiVersion: devices.kubeedge.io/v1beta1
  2. kind: DeviceModel
  3. metadata:
  4. name: beta1-model
  5. spec:
  6. properties:
  7. - name: temp
  8. description: beta1-model
  9. type: INT
  10. accessMode: ReadWrite
  11. maximum: "100"
  12. minimum: "1"
  13. unit: "Celsius"
  14. protocol: modbus

In the above example, a device model named beta1-model is defined, which uses the modbus protocol and defines a device attribute named temp, whose data type is int. In addition, the access method, value range and unit of the device attribute are also defined.

Device Instance

A device instance represents an actual device object.

The device spec is static, including device properties list, it describes the details of each property, including its name, type, access method.

Device Instance Sample

A sample device instance like below. For complete Device Instance definition, you can refer to device-instance.

  1. apiVersion: devices.kubeedge.io/v1beta1
  2. kind: Device
  3. metadata:
  4. name: beta1-device
  5. spec:
  6. deviceModelRef:
  7. name: beta1-model
  8. nodeName: worker-node1
  9. properties:
  10. - name: temp
  11. collectCycle: 10000000000 # The frequency of reporting data to the cloud, once every 10 seconds
  12. reportCycle: 10000000000 # The frequency of data push to user applications or databases, once every 10 seconds
  13. reportToCloud: true
  14. desired:
  15. value: "30"
  16. pushMethod:
  17. mqtt:
  18. address: tcp://127.0.0.1:1883
  19. topic: temp
  20. qos: 0
  21. retained: false
  22. dbMethod:
  23. influxdb2:
  24. influxdb2ClientConfig:
  25. url: http://127.0.0.1:8086
  26. org: test-org
  27. bucket: test-bucket
  28. influxdb2DataConfig:
  29. measurement: stat
  30. tag:
  31. unit: temperature
  32. fieldKey: beta1test
  33. visitors:
  34. protocolName: modbus
  35. configData:
  36. register: "HoldingRegister"
  37. offset: 2
  38. limit: 1
  39. scale: 1
  40. isSwap: true
  41. isRegisterSwap: true
  42. protocol:
  43. protocolName: modbus
  44. configData:
  45. ip: 172.17.0.3
  46. port: 1502

In the above example, a device named beta1-device is defined, the model associated with it is beta1-model, and the node where the device runs is worker-node1. It defines device properties in the spec.properties field, including message reporting frequency, message push method (spec.properties.pushMethod), and parameters required to access the device (spec.properties.visitors). In addition, the protocol used by the device is defined in the spec.protocol field.

Usage of Device CRD

The following are the steps to

  1. Create a device model, execute in the cloud node.

    1. kubectl apply -f <path to device model yaml>
  2. Create a device instance, execute in the cloud node.

    1. kubectl apply -f <path to device instance yaml>