kubeedge-counter-demo(一) 2020-11-30 笔记,实验 暂无评论 1549 次阅读 先说这是什么事。下载了一个kubeedge的官方例程`kubeedge-counter-demo`,这个例程是用树莓派当成一个计数器(终端设备),通过网页来开关计数器、查看计数器的值。我把网页部分部署出来了。 ![](https://www.proup.club/usr/uploads/2020/11/1354350029.png) ![](https://www.proup.club/usr/uploads/2020/11/3650021003.png) 以下均在 cloud 操作(192.168.56.103) [TOC] ## 前期准备: 下载:[examples/kubeedge-counter-demo/crds at master · kubeedge/examples (github.com)](https://github.com/kubeedge/examples) ,装到云端的 `$GOPATH/src/github.com/kubeedge/examples` ## 打包并上传镜像 参考:[(1条消息) Docker中上传镜像到docker hub中_sk_Grace的博客-CSDN博客_dockerhub](https://blog.csdn.net/sk_grace/article/details/81220675) ### 打包镜像 ``` cd $GOPATH/src/github.com/kubeedge/examples/kubeedge-counter-demo/web-controller-app go build -o kubeedge-counter-controller main.go docker build . -t kubeedge/kubeedge-counter-app:v1.0.0 ``` ### 测试镜像 ``` docker run -p 80:80 kubeedge/kubeedge-counter-app:v1.0.0 ``` 这时候浏览器访问192.168.54.103,可以看到网页。 ### 上传镜像 看一下镜像: ``` root@cloud:.../kubeedge-counter-demo/web-controller-app# docker images REPOSITORY TAG IMAGE ID CREATED SIZE kubeedge/kubeedge-counter-app v1.0.0 1d5cbf7e4f13 16 minutes ago 90.4MB ubuntu 18.04 2c047404e52d 4 days ago 63.3MB kindest/node v1.19.1 37ddbc9063d2 2 months ago 1.33GB centos 7.6.1810 f1cb7c7d58b7 20 months ago 202MB ``` 给镜像打标签:`docker tag IMAGEID(镜像id) REPOSITORY:TAG(仓库:标签)` ``` docker tag 1d5cbf7e4f13 pro1515151515/kubeedge-counter-app:v1.0.0 ``` 正式上传: ``` docker login --username=pro1515151515 registry.cn-hangzhou.aliyuncs.com docker push pro1515151515/kubeedge-counter-app:v1.0.0 ``` >结果: > >``` >root@cloud:.../web-controller-app# docker push pro1515151515/kubeedge-counter-app:v1.0.0 >The push refers to repository [docker.io/pro1515151515/kubeedge-counter-app] >a2994fb790dd: Pushed 233ab4db1c31: Pushed bac76ec36208: Pushed fe6d8881187d: Mounted from library/ubuntu 23135df75b44: Mounted from library/ubuntu b43408d5f11b: Mounted from library/ubuntu v1.0.0: digest: sha256:221b5abb49f58404dd358d622410d9c7794f8ff2b9527b7f68df323f031df893 size: 1573 >``` > >用edge(192.168.56.101),能拉下来: > >``` >root@kubeedge:~# docker pull pro1515151515/kubeedge-counter-app:v1.0.0 >v1.0.0: Pulling from pro1515151515/kubeedge-counter-app >f22ccc0b8772: Downloading [=============================> ] 15.83MB/26.71MB 3cf8fb62ba5f: Download complete e80c964ece6a: Download complete 27472dd62a56: Download complete da7ad24336f9: Waiting 45d23732f4c6: Waiting >``` ## 修改crd文件 ``` cd $GOPATH/src/github.com/kubeedge/examples/kubeedge-counter-demo/crds vim kubeedge-web-controller-app.yaml ``` 将其中的` image: kubeedge/kubeedge-counter-app:v1.0.0 `替换成` image: pro1515151515/kubeedge-counter-app:v1.0.0 ` ## 部署 ``` cd $GOPATH/src/github.com/kubeedge/examples/kubeedge-counter-demo/crds kubectl create -f kubeedge-web-controller-app.yaml ``` > ``` > deployment.apps/kubeedge-counter-app created > ``` ### 查看Pods ``` kubectl get pods ``` > ``` > root@cloud:.../crds# kubectl get pods > NAME READY STATUS RESTARTS AGE > kubeedge-counter-app-fc6d947d8-n92mn 0/1 ContainerCreating 0 34s > ``` > ### 查看Pod详情 ``` kubectl describe pod kubeedge-counter-app ``` > ``` > root@cloud:/home/pro/go/src/github.com/kubeedge/examples/kubeedge-counter-demo/crds# kubectl describe pod kubeedge-counter-app > Name: kubeedge-counter-app-fc6d947d8-rvmn2 > Namespace: default > Priority: 0 > Node: kind-control-plane/172.18.0.2 > Start Time: Mon, 30 Nov 2020 10:32:14 +0000 > Labels: k8s-app=kubeedge-counter-app > pod-template-hash=fc6d947d8 > Annotations: > Status: Running > IP: 172.18.0.2 > IPs: > IP: 172.18.0.2 > Controlled By: ReplicaSet/kubeedge-counter-app-fc6d947d8 > Containers: > kubeedge-counter-app: > Container ID: containerd://07a8e2954c4c3db7aba82e0ee24045ef31df372b78d1d9aabf535c4b2e76b5e3 > Image: pro1515151515/kubeedge-counter-app:v1.0.0 > Image ID: docker.io/pro1515151515/kubeedge-counter-app@sha256:221b5abb49f58404dd358d622410d9c7794f8ff2b9527b7f68df323f031df893 > Port: > Host Port: > State: Running > Started: Mon, 30 Nov 2020 10:33:04 +0000 > Ready: True > Restart Count: 0 > Environment: > Mounts: > /var/run/secrets/kubernetes.io/serviceaccount from default-token-xnv4t (ro) > Conditions: > Type Status > Initialized True > Ready True > ContainersReady True > PodScheduled True > Volumes: > default-token-xnv4t: > Type: Secret (a volume populated by a Secret) > SecretName: default-token-xnv4t > Optional: false > QoS Class: BestEffort > Node-Selectors: node-role.kubernetes.io/master= > Tolerations: node-role.kubernetes.io/master:NoSchedule > node.kubernetes.io/not-ready:NoExecute for 300s > node.kubernetes.io/unreachable:NoExecute for 300s > Events: > Type Reason Age From Message > ---- ------ ---- ---- ------- > Normal Scheduled 2m39s default-scheduler Successfully assigned default/kubeedge-counter-app-fc6d947d8-rvmn2 to kind-control-plane > Normal Pulling 2m39s kubelet Pulling image "pro1515151515/kubeedge-counter-app:v1.0.0" > Normal Pulled 111s kubelet Successfully pulled image "pro1515151515/kubeedge-counter-app:v1.0.0" in 48.847175212s > Normal Created 110s kubelet Created container kubeedge-counter-app > Normal Started 110s kubelet Started container kubeedge-counter-app > ``` ### SSH正向代理 Cloud:192.168.56.103(外部可访问) Cloud与kind集群的虚拟内网:172.18.0.0/24,其中Cloud是172.18.0.1,网页部署在172.18.0.2:80(外部访问不了) 目标:外部访问192.168.56.103,自动转接172.18.0.2。 ``` ssh -Nfg -L 0.0.0.0:80:172.18.0.2:80 192.168.56.103 ``` > 行不通的东西(一):kubectl的expose暴露端口 > > ``` > kubectl expose pod kubeedge-counter-app-fc6d947d8-vrd67 --port=80 --external-ip=192.168.54.103 > ``` > > Pod的172.18.0.2,是kind集群里另一个节点的地址。kind集群内网里,cloud的IP是172.18.0.1。也就是不能用这个暴露方法。得用NAT。 > 行不通的东西(二):用防火墙设置NAT > > ```bash > 用防火墙设置NAT > iptables -F > iptables -P INPUT ACCEPT > iptables -P FORWARD ACCEPT > iptables -t nat -A PREROUTING --dst 192.168.56.103 -p tcp --dport 80 -j DNAT --to-destination 172.18.0.2:80 > iptables -t nat -A POSTROUTING --dst 172.18.0.2 -p tcp --dport 80 -j SNAT --to-source 192.168.56.103 > > 看刚才设了多少个NAT规则: > iptables -t nat -L -n > > 删掉第一条NAT规则 > iptables -t nat -D POSTROUTING 1 > iptables -t nat -D PREROUTING 1 > ``` > > 亲测无效。 ## 删除部署 先看一下有什么部署 ``` kubectl get deployment ``` > ``` > root@cloud:.../crds# kubectl get deployment > NAME READY UP-TO-DATE AVAILABLE AGE > kubeedge-counter-app 0/1 1 0 94s > ``` > > 删除部署: ``` kubectl delete deployment kubeedge-counter-app ``` > ``` > root@cloud:.../crds# kubectl delete deployment kubeedge-counter-app > deployment.apps "kubeedge-counter-app" deleted > ``` 标签: kubeedge 本作品采用 知识共享署名-相同方式共享 4.0 国际许可协议 进行许可。
评论已关闭