k8s删除deployment_13 捣鼓 K8S 基本组件 Deployment 和 Service
K8S 基本组件 - Deployment 和 Servcie先创建一个ClusterIP服务创建deploymentkubectl run nginx --image katacoda/docker-http-server:latest --replicas 3列出deploymentkubectl get deployment观察deploymentkubectl describe de...

K8S 基本组件 - Deployment 和 Servcie
先创建一个ClusterIP服务
创建deployment
kubectl run nginx --image katacoda/docker-http-server:latest --replicas 3

列出deployment
kubectl get deployment

观察deployment
kubectl describe deployment nginx

列出replicaset
kubectl get replicaset

观察replicaset
kubectl describe replicaset nginx-******

列出pod
kubectl get pod -o wide

使用ClusterIP的方式发布服务
kubectl expose deployment nginx --port 80 --target-port 80 --type ClusterIP --selector=run=nginx --name nginx
列出服务
kubectl get service

观察service
kubectl describe service nginx

根据上条命令观察到的clusterip访问服务,同时对比此前观察的pod id
curl http://clusterip

重复n次,可以观察三个pod之间的负载均衡效果
扩展服务到5个副本
kubectl scale deployment nginx --replicas=5

观察deployment变化情况
kubectl describe deployment nginx
观察服务变化情况
kubectl describe service nginx

观察pod变化情况
kubectl get pod -o wide

收缩服务到2个副本
kubectl scale deployment nginx --replicas=2

列出replicaset
kubectl get replicaset

观察replicaset变化
kubectl describe replicaset nginx-******

观察pod情况
kubectl get pod -o wide

删除服务
kubectl delete service nginx
删除部署
kubectl delete deployment nginx

再来创建一个 NodePort 服务
创建 deployment
kubectl run simple-web --replicas=3 --image=katacoda/docker-http-server:latest --port=80

列出pod
kubectl get pod -o wide

发布 service
kubectl expose deployment simple-web --type=NodePort --name=simple-web
列出 service
kubectl get service

观察service
kubectl describe service simple-web

如命令回显所示,该服务的NodePort为31206
使用浏览器访问http://hostip:nodeprot



Ctrl F5 n次,可以观察三个pod之间的负载均衡效果
删除 service
kubectl delete service simple-web
删除 deployment
kubectl delete deployment simple-web

更多推荐
所有评论(0)