Shifu 是一个 Kubernetes 原生的IoT设备虚拟化框架。Shifu 希望帮助IoT应用开发者以即插即用的方式实现IoT设备的虚拟化、监视、管控和自动化。本文通过在本地集群中部署Shifu,完成通过MQTT、Http等方式接入物联设备,体验了用容器开发的路径完成物联网应用开发。
Shifu官网:https://shifu.run/zh-Hans/ Github仓库:https://github.com/Edgenesis/shifu
# 启动Docker
$ open -a docker
# 创建集群
$ sudo kind create cluster --image="kindest/node:v1.24.0"
# 提前准备镜像导入集群
$ sudo docker pull quay.io/brancz/kube-rbac-proxy:v0.12.0
$ sudo docker pull edgehub/shifu-controller:v0.1.1
$ sudo docker pull nginx:1.21
$ sudo kind load docker-image quay.io/brancz/kube-rbac-proxy:v0.12.0 edgehub/shifu-controller:v0.1.1 nginx:1.21
# 安装shifu
$ git clone https://github.com/Edgenesis/shifu.git
$ cd shifu
$ sudo kubectl apply -f pkg/k8s/crd/install/shifu_install.yml
# 跑一个应用程序
$ sudo kubectl run --image=nginx:1.21 nginx
# shellA
$ mosquitto_sub -h 82.157.170.202 -t topic0
# shellB
$ mosquitto_pub -h 82.157.170.202 -t topic0 -m "哈哈哈"
$ sudo docker pull edgehub/deviceshifu-http-mqtt:v0.1.1
$ sudo kind load docker-image edgehub/deviceshifu-http-mqtt:v0.1.1
$ sudo kubectl apply -f examples/my_mqtt/mqtt_deploy
$ sudo kubectl exec -it nginx -- bash
$ curl http://deviceshifu-mqtt.deviceshifu.svc.cluster.local/mqtt_data
$ cd api_thermometer
$ uvicorn --host 0.0.0.0 --port 23330 main:app
$ cd api_led
$ uvicorn --host 0.0.0.0 --port 23331 main:app
$ curl http://localhost:23330/temperature
$ curl http://localhost:23330/humidity
$ curl http://localhost:23331/setfloat\?value\=123.4
http_thermometer/deployment/http_edgedevice.yaml
中ip地址。http_led/deployment/http_edgedevice.yaml
中ip地址。$ sudo docker pull edgehub/deviceshifu-http-http:v0.1.1
$ sudo kind load docker-image edgehub/deviceshifu-http-http:v0.1.1
$ sudo kubectl apply -f examples/my_http_led/deployment
$ sudo kubectl apply -f examples/my_http_thermometer/deployment
$ sudo kubectl exec -it nginx -- bash
$ curl http://my-thermometer.deviceshifu.svc.cluster.local/temperature
$ curl http://my-thermometer.deviceshifu.svc.cluster.local/humidity
$ curl http://my-led.deviceshifu.svc.cluster.local/setfloat?value=23.4
将温度和湿度读取,然后在LED上面间歇显示出来。
$ sudo docker build -t yangxijie/connection:v0.0.1 .
$ sudo docker images | grep connection
yangxijie/connection v0.0.1 a9526147ddad 2 minutes ago 125MB
$ sudo kind load docker-image yangxijie/connection:v0.0.1
$ sudo kubectl run --image=yangxijie/connection:v0.0.1 connection-name
$ sudo docker pull edgehub/deviceshifu-http-http:v0.1.1
$ sudo docker pull edgehub/plc-device:v0.0.1
$ sudo kind load docker-image edgehub/deviceshifu-http-http:v0.1.1 edgehub/plc-device:v0.0.1
$ sudo kubectl apply -f examples/my_plc/plc-deployment
$ sudo kubectl run nginx --image=nginx:1.21 -n deviceshifu
$ sudo kubectl exec -it nginx -n deviceshifu -- bash
$ curl "deviceshifu-plc/sendsinglebit?rootaddress=Q&address=0&start=0&digit=1&value=1"; echo
获取摄像头ip地址,修改rtsp/camera-deployment/deviceshifu-camera-deployment.yaml
中的ip地址
$ sudo docker pull edgehub/deviceshifu-http-http:v0.1.1
$ sudo docker pull edgehub/camera-python:v0.0.1
$ sudo kind load docker-image edgehub/deviceshifu-http-http:v0.1.1 edgehub/camera-python:v0.0.1
$ sudo kubectl apply -f examples/my_rtsp/camera-deployment
# 集群中使用curl交互
$ sudo kubectl exec -it nginx -- bash
$ curl http://deviceshifu-camera.deviceshifu.svc.cluster.local/info
# 本机浏览器访问
$ sudo kubectl port-forward svc/deviceshifu-camera -n deviceshifu 8080:80
# 输入`localhost:8080/info`查看信息
# 输入`localhost:8080/capture`获取图片
# 输入`localhost:8080/move/{up|down|left|right}`操控相机位置
# 输入`localhost:8080/stream?timeout=0`获取实时视频流
本文由边无际授权发布