kubebuilder实战之六:构建部署运行 (5)

这还不够!还有个重要的信息需要咱们检查---controller的日志,先看有哪些pod:

zhaoqin@zhaoqindeMBP-2 elasticweb % kubectl get pods --all-namespaces NAMESPACE NAME READY STATUS RESTARTS AGE dev elasticweb-sample-56fc5848b7-559lw 1/1 Running 0 68s dev elasticweb-sample-56fc5848b7-hp4wv 1/1 Running 0 68s elasticweb-system elasticweb-controller-manager-5795d4d98d-t6jvc 2/2 Running 0 98s kube-system coredns-7f89b7bc75-5pdwc 1/1 Running 15 20d kube-system coredns-7f89b7bc75-nvbvm 1/1 Running 15 20d kube-system etcd-hedy 1/1 Running 15 20d kube-system kube-apiserver-hedy 1/1 Running 15 20d kube-system kube-controller-manager-hedy 1/1 Running 16 20d kube-system kube-flannel-ds-v84vc 1/1 Running 22 20d kube-system kube-proxy-hlppx 1/1 Running 15 20d kube-system kube-scheduler-hedy 1/1 Running 16 20d test-clientset client-test-deployment-7677cc9669-kd7l7 1/1 Running 9 9d test-clientset client-test-deployment-7677cc9669-kt5rv 1/1 Running 9 9d

可见controller的pod名称为elasticweb-controller-manager-5795d4d98d-t6jvc,执行以下命令可以查看日志,多了-c manager参数是因为这个pod里面有两个容器,需要指定正确的容器才能看到日志:

kubectl logs -f \ elasticweb-controller-manager-5795d4d98d-t6jvc \ -c manager \ -n elasticweb-system

再次看到了熟悉的业务日志:

2021-02-21T08:52:27.064Z INFO controllers.ElasticWeb 1. start reconcile logic {"elasticweb": "dev/elasticweb-sample"} 2021-02-21T08:52:27.064Z INFO controllers.ElasticWeb 3. instance : Image [tomcat:8.0.18-jre8], Port [30003], SinglePodQPS [500], TotalQPS [600], RealQPS [nil] {"elasticweb": "dev/elasticweb-sample"} 2021-02-21T08:52:27.064Z INFO controllers.ElasticWeb 4. deployment not exists {"elasticweb": "dev/elasticweb-sample"} 2021-02-21T08:52:27.064Z INFO controllers.ElasticWeb set reference {"func": "createService"} 2021-02-21T08:52:27.064Z INFO controllers.ElasticWeb start create service {"func": "createService"} 2021-02-21T08:52:27.107Z INFO controllers.ElasticWeb create service success {"func": "createService"} 2021-02-21T08:52:27.107Z INFO controllers.ElasticWeb expectReplicas [2] {"func": "createDeployment"} 2021-02-21T08:52:27.107Z INFO controllers.ElasticWeb set reference {"func": "createDeployment"} 2021-02-21T08:52:27.107Z INFO controllers.ElasticWeb start create deployment {"func": "createDeployment"} 2021-02-21T08:52:27.119Z INFO controllers.ElasticWeb create deployment success {"func": "createDeployment"} 2021-02-21T08:52:27.119Z INFO controllers.ElasticWeb singlePodQPS [500], replicas [2], realQPS[1000] {"func": "updateStatus"} 2021-02-21T08:52:27.198Z DEBUG controller-runtime.controller Successfully Reconciled {"controller": "elasticweb", "request": "dev/elasticweb-sample"} 2021-02-21T08:52:27.198Z INFO controllers.ElasticWeb 1. start reconcile logic {"elasticweb": "dev/elasticweb-sample"} 2021-02-21T08:52:27.198Z INFO controllers.ElasticWeb 3. instance : Image [tomcat:8.0.18-jre8], Port [30003], SinglePodQPS [500], TotalQPS [600], RealQPS [1000] {"elasticweb": "dev/elasticweb-sample"} 2021-02-21T08:52:27.198Z INFO controllers.ElasticWeb 9. expectReplicas [2], realReplicas [2] {"elasticweb": "dev/elasticweb-sample"} 2021-02-21T08:52:27.198Z INFO controllers.ElasticWeb 10. return now {"elasticweb": "dev/elasticweb-sample"} 2021-02-21T08:52:27.198Z DEBUG controller-runtime.controller Successfully Reconciled {"controller": "elasticweb", "request": "dev/elasticweb-sample"}

再用浏览器验证tomcat已经启动成功;

卸载和清理

体验完毕后,如果想把前面创建的资源全部清理掉(注意,是清理资源,不是资源对象),可以执行以下命令:

make uninstall

至此,整个operator的设计、开发、部署、验证流程就全部完成了,在您的operator开发过程中,希望本文能给您带来一些参考;

你不孤单,欣宸原创一路相伴

Java系列

Spring系列

Docker系列

kubernetes系列

数据库+中间件系列

DevOps系列

欢迎关注公众号:程序员欣宸

微信搜索「程序员欣宸」,我是欣宸,期待与您一同畅游Java世界...
https://github.com/zq2599/blog_demos

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zwpygj.html