Using kubectl to Create a Deployment
学习如何部署app使用kubctl
创建部署以下为重点节录,取自官网
Once the application instances are created, a Kubernetes Deployment Controller continuously monitors those instances. If the Node hosting an instance goes down or is deleted, the Deployment controller replaces the instance with an instance on another Node in the cluster. This provides a self-healing mechanism to address machine failure or maintenance.
大意是只说当你当你创建app instance后,k8s会持续地帮你监控,如果该Node託管的instance坏掉,会自动起一个新的Instance
这是个重要概念,这提供了当你的服务坏掉或是需要维修重启,k8s具有自我修复的方法
Interactive Tutorial - Deploying an App
接着是在网页上开始实作,minikube/kubectl不需要安装
查看kubectl资讯kubectl version
查看可任何command的附加资讯或是参数,在最后加上--help,kubectl get nodes
可以查看可用Nodekubectl get nodes --help
透过image部署kubectl create deployment kubernetes-bootcamp --image=gcr.io/google-samples/kubernetes-bootcamp:v1
当在执行部属时,k8s会做这几件事
searched for a suitable node where an instance of the application could be run (we have only 1 available node)scheduled the application to run on that Nodeconfigured the cluster to reschedule the instance on a new Node when needed查看部署清单kubectl get deployments
建立kubernetes proxy(检视app)pod是运行在k8s内部被隔离的网路,所以其中一种访问到pod内的方法就是建立proxy
kubectl proxy
接着使用curl http://localhost:8001/version
就能访问到pod
在教学中的API Server还会为每个pod建立endpoint
但是好像是失效的,在echo $POD_NAME是空的
不过照着教学export pod name在用curl继续访问是可以拿到一串带有href的网址的