本文是基于github上提供的kubeedge-counter-demo进行的。
1)kubeedge v1.3.1版本安装成功,并正常运行。
2)本文接下来的验证将使用边缘节点bluejoy-jing进行(如果你参考本文进行相关验证,后续边缘节点名称的配置需要根据你的实际情况进行更改)。
3)本示例要求的kubeedge版本必须是v1.2.1+ 。
4)确保kubernetes apiserver开启了以下配置:
--insecuret-port=8080
--insecure-bind-address=0.0.0.0
可以通过修改/etc/kubernetes/manifests/kube-apiserver.yaml文件,并重启k8s-apiserver组件的pod来进行更改。
5)从github上clone示例代码
mkdir /home/bluejoy/kubeedge/kubeedge-example/
git clone https://github.com/kubeedge/examples.git
cd /home/bluejoy/kubeedge/kubeedge-example/examples/kubeedge-counter-demo/crds
kubectl create -f kubeedge-counter-model.yaml
根据你的实际情况修改matchExpressions:
cd /home/bluejoy/kubeedge/kubeedge-example/examples/kubeedge-counter-demo/crds
vim kubeedge-counter-instance.yaml
apiVersion: devices.kubeedge.io/v1alpha1
kind: Device
metadata:
name: counter
labels:
description: 'counter'
manufacturer: 'test'
spec:
deviceModelRef:
name: counter-model
nodeSelector:
nodeSelectorTerms:
- matchExpressions:
- key: 'kubernetes.io/hostname'
operator: In
values:
- bluejoy-jing
status:
twins:
- propertyName: status
desired:
metadata:
type: string
value: 'OFF'
reported:
metadata:
type: string
value: '0'
kubectl create -f kubeedge-counter-instance.yaml
web-controller-app程序默认监听的端口号为80,此处修改为8089,如下所示:
cd /home/bluejoy/kubeedge/kubeedge-example/examples/kubeedge-counter-demo/web-controller-app
vim main.go
package main
import (
"github.com/astaxie/beego"
"github.com/kubeedge/examples/kubeedge-counter-demo/web-controller-app/controller"
)
func main() {
beego.Router("/", new(controllers.TrackController), "get:Index")
beego.Router("/track/control/:trackId", new(controllers.TrackController), "get,post:ControlTrack")
beego.Run(":8089")
}
cd /home/bluejoy/kubeedge/kubeedge-example/examples/kubeedge-counter-demo/web-controller-app
make all
make docker
注意:构建镜像时,请将源码拷贝到GOPATH对应的路径下,如果开启了go mod请关闭。
cd /home/bluejoy/kubeedge/kubeedge-example/examples/kubeedge-counter-demo/crds
kubectl apply -f kubeedge-web-counter-app.yaml
3.4 查看部署结果
在浏览器中打开如下网址:http://192.168.56.105:8089/
cd /home/bluejoy/kubeedge/kubeedge-example/examples/kubeedge-counter-demo/counter-mapper
make all
make docker
注意:构建镜像时,请将源码拷贝到GOPATH对应的路径下,如果开启了go mod请关闭。
cd /home/bluejoy/kubeedge/kubeedge-example/examples/kubeedge-counter-demo/crds
kubectl apply -f kubeedge-pi-counter-app.yaml
在浏览器中打开如下网址:http://192.168.56.105:8089/
在web页面上选择ON,并点击Execute,可以再edge节点上通过以下命令查看执行结果:
docker logs -f counter-container-id
在web页面上选择STATUS,并点击Execute,会在Web页面上返回counter当前的status,如下所示:
也可以在云端通过如下命令查看status的值:
kubectl get device counter -o yaml -w
在web页面上选择OFF,并点击Execute,可以再edge节点上通过以下命令查看执行结果:
docker logs -f counter-container-id