k8s(5)-拓展服務

    

   在以前咱們建立了一個部署,而後經過服務公開它部署只建立了一個Pod來運行咱們的應用程序。當流量增長時,咱們須要擴展應用程序以知足用戶需求。bash

經過更改部署中的副本數來完成擴展。mvc

 

 

 

1. 拓展部署

 這裏將拓展副本到4個負載均衡

[root@master ~]# kubectl scale deployments/kubernetes-bootcamp --replicas=4
deployment.extensions/kubernetes-bootcamp scaled
[root@master ~]# kubectl get deployment
NAME                  READY   UP-TO-DATE   AVAILABLE   AGE
kubernetes-bootcamp   4/4     4            4           5h11m

 

2. 查看副本是否都運行
[root@master ~]# kubectl get pods -o wide
NAME                                   READY   STATUS    RESTARTS   AGE     IP            NODE     NOMINATED NODE   READINESS GATES
kubernetes-bootcamp-7f56b875dc-6zbjt   1/1     Running   0          5h12m   10.244.0.15   master   <none>           <none>
kubernetes-bootcamp-7f56b875dc-cp7cq   1/1     Running   0          47s     10.244.0.16   master   <none>           <none>
kubernetes-bootcamp-7f56b875dc-n4wkn   1/1     Running   0          47s     10.244.0.17   master   <none>           <none>
kubernetes-bootcamp-7f56b875dc-pmvck   1/1     Running   0          47s     10.244.0.18   master   <none>           <none>

 

3. 咱們如今有4個Pod了,能夠經過describe查看event變化
[root@master ~]# kubectl describe deployments/kubernetes-bootcamp
Name:                   kubernetes-bootcamp
.....
.....
  Type           Status  Reason
  ----           ------  ------
  Progressing    True    NewReplicaSetAvailable
  Available      True    MinimumReplicasAvailable
OldReplicaSets:  <none>
NewReplicaSet:   kubernetes-bootcamp-7f56b875dc (4/4 replicas created)
Events:
  Type    Reason             Age    From                   Message
  ----    ------             ----   ----                   -------
  Normal  ScalingReplicaSet  4m28s  deployment-controller  Scaled up replica set kubernetes-bootcamp-7f56b875dc to 4

  

4. 訪問應用查看是否有負載均衡的效果
[root@master ~]# curl http://192.168.0.10:31238
Hello Kubernetes bootcamp! | Running on: kubernetes-bootcamp-7f56b875dc-6zbjt | v=1
[root@master ~]# curl http://192.168.0.10:31238
Hello Kubernetes bootcamp! | Running on: kubernetes-bootcamp-7f56b875dc-cp7cq | v=1
[root@master ~]# curl http://192.168.0.10:31238
Hello Kubernetes bootcamp! | Running on: kubernetes-bootcamp-7f56b875dc-pmvck | v=1
[root@master ~]# curl http://192.168.0.10:31238
Hello Kubernetes bootcamp! | Running on: kubernetes-bootcamp-7f56b875dc-n4wkn | v=1
[root@master ~]# 
相關文章
相關標籤/搜索