Run KubeEdge official example_Counter Demo Counter
KubeEdge Counter Demo counter is a pseudo-device, users don't need any additional physical device to run this demo. The counter runs on the edge side, and the user can control it on the web from the cloud side, or obtain the counter value from the cloud side on the web. The schematic diagram is as follows:
Install kubeedge first
Linux installation kubeedge_ pro-test success
Kubeedge edge node installation
#在k8s-master 上执行,查看节点
kubectl get node
NAME STATUS ROLES AGE VERSION
k8s-master Ready master 34h v1.19.2
k8s-node-1 Ready agent,edge 79m v1.19.3-kubeedge-v1.5.0
Cloud operations are executed on k8s-master
#下载示例代码
git clone https://github.com/kubeedge/examples.git $GOPATH/src/github.com/kubeedge/examples
#使用官方的示例仓库github会比较慢,这里可以使用我的加速仓库
git clone https://gitee.com/iot-kubeedge/kubeedge-examples.git $GOPATH/src/github.com/kubeedge/examples
#创建 device model
cd $GOPATH/src/github.com/kubeedge/examples/kubeedge-counter-demo/crds
#创建model
kubectl create -f kubeedge-counter-model.yaml
#创建device
cd $GOPATH/src/github.com/kubeedge/examples/kubeedge-counter-demo/crds
#根据你的实际情况修改matchExpressions:
vim kubeedge-counter-instance.yaml
#主要修改的地方
- key: 'kubernetes.io/hostname'
values:
- k8s-node-1 #这里是节点名称
#运行yaml
kubectl create -f kubeedge-counter-instance.yaml
#部署云端应用
#云端应用web-controller-app用来控制边缘端的pi-counter-app应用,该程序默认监听的端口号为80,此处修改为8089
cd $GOPATH/src/github.com/kubeedge/examples/kubeedge-counter-demo/web-controller-app
vim main.go
beego.Run(":8089")
#构建镜像
make all
make docker
#部署web-controller-app
cd $GOPATH/src/github.com/kubeedge/examples/kubeedge-counter-demo/crds
kubectl apply -f kubeedge-web-controller-app.yaml
#部署边缘端应用
#边缘端的pi-counter-app应用受云端应用控制,主要与mqtt服务器通信,进行简单的计数功能。
#修改代码与构建镜像
#需要将Makefile中的GOARCH修改为amd64才能运行该容器。默认是arm架构的
cd $GOPATH/src/github.com/kubeedge/examples/kubeedge-counter-demo/counter-mapper
vim Makefile
GOARCH=amd64 go build -o pi-counter-app main.go
#构建镜像
make all
make docker
#部署Pi Counter App
cd $GOPATH/src/github.com/kubeedge/examples/kubeedge-counter-demo/crds
kubectl apply -f kubeedge-pi-counter-app.yaml
#说明:为了防止Pod的部署卡在`ContainerCreating`,这里直接通过docker save、scp和docker load命令将镜像发布到边缘端
#因为边缘端没有这个镜像,只能手动弄过去,或者先上传到私有镜像仓库, 边缘端配置私有仓库地址,就可以直接从私有仓库下载
#这里就手动弄到边缘端
docker save -o kubeedge-pi-counter.tar kubeedge/kubeedge-pi-counter:v1.0.0
#传到边缘端
scp kubeedge-pi-counter.tar [email protected]:/data/
#在边缘端执行
docker load -i kubeedge-pi-counter.tar
#在边缘端查看容器启动日志,有没有报错
docker logs -f counter-container-id
docker logs -f 8e2359446752
experience demo
Both the cloud part and the edge part of KubeEdge Demo have been deployed
kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
kubeedge-counter-app-6984dcb4dd-jz5nh 1/1 Running 0 32m 172.16.72.143 k8s-master <none> <none>
kubeedge-pi-counter-784d57c5d4-27v5g 1/1 Running 0 30m <none> k8s-node-1 <none> <none>
Browser access: http://172.16.72.143:8089/Because
the hostNetwork mode is used, it can be accessed directly,
Select ON on the web page and click Execute to view the execution results on the edge node by running the following command
docker logs -f counter-container-id
docker logs -f 8e2359446752
Indicates that the test was successful
Possible problems with deployment
There is no response to the click, and the page debugging tool F12 is used to view it. The reason is that jquery cannot be accessed ------ It's a pit ------
https://code.jquery.com/jquery-1.10.2.min.js cannot be accessed
https://code.jquery.com/jquery-1.10.2.min.js
is modified to
https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js
into the container
docker ps to find kubeedge-counter -app
docker exec -it 21b11899d52f /bin/bash
cannot be modified, it is a binary file
Modify the source code, recompile and package
cd $GOPATH/src/github.com/kubeedge/examples/kubeedge-counter-demo/web-controller-app
vim views/layout.html
https://code.jquery.com/jquery-1.10.2.min.js #把这个替换成 https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js
#重新编译打包
make all
make docker
cd $GOPATH/src/github.com/kubeedge/examples/kubeedge-counter-demo/crds
#删除
kubectl delete -f kubeedge-web-controller-app.yaml
#重新启动
kubectl apply -f kubeedge-web-controller-app.yaml
Port 8080 is unreachable—it’s a trap—error: dial tcp 127.0.0.1:8080: connect: connection refused
#查看云端日志
docker ps
kubeedge-counter-app 找到容器id
docker logs -f 6e768c3db4eb
报错: dial tcp 127.0.0.1:8080: connect: connection refused
kubectl -s http://127.0.0.1:8080 get nodes
curl http://127.0.0.1:8080
8080端口不通
#查看kubelet日志
journalctl -xeu kubelet
journalctl -f -u kubelet
#报错
Failed to get system container stats for "/system.slice/docker.service": failed to get cg
原因:kubernetes和docker版本兼容性问题
vim /usr/lib/systemd/system/kubelet.service.d/10-kubeadm.conf
[Service]
CPUAccounting=true ## 添加 CPUAccounting=true 选项,开启 systemd CPU 统计功能
MemoryAccounting=true ## 添加 MemoryAccounting=true 选项,开启 systemd Memory 统计功能
systemctl daemon-reload
systemctl restart kubelet
还是没有用------------8080端口不通--------
netstat -tpnl
kubectl cluster-info
vim /etc/kubernetes/manifests/kube-apiserver.yaml
insecure-port字段值为0,表示默认禁用了8080端口
--insecure-port=8080
重启apiserver容器 -----成功8080通了-------
docker restart ce5511548fe0
We need to expose the http port 8080 of the Kubernetes apiserver to interact with cloudcore/kubectl.
Follow the steps below to enable http port in Kubernetes apiserver. In this way, commands such as kubectl get nodes -s 192.169.0.10:8080 can be executed on the edge node, just like on the master node.
kubectl get nodes -s 172.16.72.143:8080
-------The counter finally counted-------Success----------------
Visit: http://172.16.72.143:8089/View
log
docker logs -f dc59f4f3a877(kubeedge-counter-app)
docker logs -f dc59f4f3a877(kubeedge-pi-counter)
Reference link: https://www.dogfei.cn/archives/kubeedge
https://zhuanlan.zhihu.com/p/342626632