Kubernetes - Deploy an App

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可以查看可用Node
kubectl 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的网址的

参考

https://kubernetes.io/docs/tutorials/kubernetes-basics/deploy-app/deploy-intro/

关于作者: 网站小编

码农网专注IT技术教程资源分享平台,学习资源下载网站,58码农网包含计算机技术、网站程序源码下载、编程技术论坛、互联网资源下载等产品服务,提供原创、优质、完整内容的专业码农交流分享平台。

热门文章