Counter is a pseudo device that user can run this demo without any extra physical devices.
Counter run at edge side, and user can control it in web from cloud side, also can get counter value in web from cloud side.
- RaspBerry PI (RaspBerry PI 4 has been used for this demo).
-
A running Kubernetes cluster.
NOTE:
add follows
--insecure-port=8080
and--insecure-bind-address=0.0.0.0
options into /etc/kubernetes/manifests/kube-apiserver.yaml -
KubeEdge v1.5+
-
MQTT Broker is running on Raspi.
With the Device CRD APIs now installed in the cluster, we create the device model and instance for the counter using the yaml files.
$ cd $GOPATH/src/github.com/kubeedge/examples/kubeedge-counter-demo
# replace "<your edge node name>" with your edge node name
$ sed -i "s#edge-node#<your edge node name>#" crds/kubeedge-counter-instance.yaml
$ kubectl create -f crds/kubeedge-counter-model.yaml
$ kubectl create -f crds/kubeedge-counter-instance.yaml
The KubeEdge Web App runs in a VM on cloud.
$ cd $GOPATH/src/github.com/kubeedge/examples/kubeedge-counter-demo/web-controller-app
$ make
$ make docker
$ cd $GOPATH/src/github.com/kubeedge/examples/kubeedge-counter-demo/crds
$ kubectl create -f kubeedge-web-controller-app.yaml
Note: instance must be created after model and deleted before model.
The KubeEdge Counter App run in raspi.
$ cd $GOPATH/src/github.com/kubeedge/examples/kubeedge-counter-demo/counter-mapper
$ make
$ make docker
$ cd $GOPATH/src/github.com/kubeedge/examples/kubeedge-counter-demo/crds
$ kubectl create -f kubeedge-pi-counter-app.yaml
The App will subscribe to the $hw/events/device/counter/twin/update/document
topic, and when it receives the expected control command on the topic, it will turn on/off the counter, also it will fresh counter value and publish value to $hw/events/device/counter/twin/update
topic, then the latest counter status will be sychronized between edge and cloud.
At last, user can get the counter status at cloud side.
-
Visit web app page by the web app link
MASTER_NODE_IP:80
. -
Choose
ON
option, and clickExecute
, then user can see counter start to count bydocker logs -f counter-container-id
at edge side. -
Choose
STATUS
option, then clickExecute
to get the counter status, finally counter status and current counter value will display in web.also you can watch counter status by
kubectl get device counter -o yaml -w
at cloud side. -
Choose
OFF
option, and clickExecute
, counter stop work at edge side.