github.com/jingruilea/kubeedge@v1.2.0-beta.0.0.20200410162146-4bb8902b3879/docs/guides/device_crd_guide.md (about) 1 # Device Management User Guide 2 3 KubeEdge supports device management with the help of Kubernetes [CRDs](https://kubernetes.io/docs/concepts/extend-kubernetes/api-extension/custom-resources/#customresourcedefinitions) and a Device Mapper (explained below) corresponding to the device being used. 4 We currently manage devices from the cloud and synchronize the device updates between edge nodes and cloud, with the help of device controller and device twin modules. 5 6 7 ## Device Model 8 9 A `device model` describes the device properties exposed by the device and property visitors to access these properties. A device model is like a reusable template using which many devices can be created and managed. 10 11 Details on device model definition can be found [here](https://github.com/kubeedge/kubeedge/blob/master/docs/proposals/device-crd.md#device-model-type-definition). 12 13 A sample device model can be found [here](https://github.com/kubeedge/kubeedge/blob/master/docs/proposals/device-crd.md#device-model-sample) 14 15 16 ## Device Instance 17 18 A `device` instance represents an actual device object. It is like an instantiation of the `device model` and references properties defined in the model. The device spec is static while the device status contains dynamically changing data like the desired state of a device property and the state reported by the device. 19 20 Details on device instance definition can be found [here](https://github.com/kubeedge/kubeedge/blob/master/docs/proposals/device-crd.md#device-instance-type-definition). 21 22 A sample device model can be found [here](https://github.com/kubeedge/kubeedge/blob/master/docs/proposals/device-crd.md#device-instance-sample). 23 24 25 ## Device Mapper 26 27 Mapper is an application that is used to connect and and control devices. Following are the responsibilities of mapper: 28 1) Scan and connect to the device. 29 2) Report the actual state of twin-attributes of device. 30 3) Map the expected state of device-twin to actual state of device-twin. 31 4) Collect telemetry data from device. 32 5) Convert readings from device to format accepted by KubeEdge. 33 6) Schedule actions on the device. 34 7) Check health of the device. 35 36 Mapper can be specific to a protocol where standards are defined i.e Bluetooth, Zigbee, etc or specific to a device if it a custom protocol. 37 38 Mapper design details can be found [here](https://github.com/kubeedge/kubeedge/blob/master/docs/proposals/mapper-design.md#mapper-design) 39 40 An example of a mapper application created to support bluetooth protocol can be found [here](https://github.com/kubeedge/kubeedge/tree/master/device/bluetooth_mapper#bluetooth-mapper) 41 42 43 ## Usage of Device CRD 44 45 The following are the steps to 46 47 1. Create a device model in the cloud node. 48 49 ```shell 50 kubectl apply -f <path to device model yaml> 51 ``` 52 53 2. Create a device instance in the cloud node. 54 55 ```shell 56 kubectl apply -f <path to device instance yaml> 57 ``` 58 59 Note: Creation of device instance will also lead to the creation of a config map which will contain information about the devices which are required by the mapper applications 60 The name of the config map will be as follows: device-profile-config-< edge node name >. The updation of the config map is handled internally by the device controller. 61 62 3. Run the mapper application corresponding to your protocol. 63 64 4. Edit the status section of the device instance yaml created in step 2 and apply the yaml to change the state of device twin. This change will be reflected at the edge, through the device controller 65 and device twin modules. Based on the updated value of device twin at the edge the mapper will be able to perform its operation on the device. 66 67 5. The reported values of the device twin are updated by the mapper application at the edge and this data is synced back to the cloud by the device controller. User can view the update at the cloud by checking his device instance object. 68 69 ```shel 70 Note: Sample device model and device instance for a few protocols can be found at $GOPATH/src/github.com/kubeedge/kubeedge/build/crd-samples/devices 71 ```