iT邦幫忙

0

Kubernetes - Scale Your App

  • 分享至 

  • xImage
  •  

Running Multiple Instances of Your App

  • 使用kubectl擴展app

Scaling

Scaling是透過改變Deployment的Replicas的數量來實現的

透過Scaling,Deployment將會確保新的Pods會被調度再有可用資源的Node上,且將Pod所需的數量增加到新的要求數目
k8s支援pods的autoscaling,但這部分不會在此解說,但必須知道的是有可能透過autoscaling會將Deployment的所有pods全數終止的情形發生

運行多個app時需要一個方法將流量分配,而service具有一個集成的load-blacer,將會把流量分配給對外開放的Deployment中的pods,且會持續的監控這些pods的endpoints,以確保能夠將流量輸送到這些pods中

而一旦你有了多個app運行,你將能夠使用滾動式更新
這是個重要的概念,將會決定service的部署策略

Interactive Tutorial - Scaling Your App

Step 1: Scaling a deployment

  • 首先列出deployments list kubectl get deployments 接著會顯示幾項資訊

    • NAME lists the names of the Deployments in the cluster.
    • READY shows the ratio of CURRENT/DESIRED replicas
    • UP-TO-DATE displays the number of replicas that have been updated to achieve the desired state.
    • AVAILABLE displays how many replicas of the application are available to your users.
    • AGE displays the amount of time that the application has been running.
  • 接著列出透過這個deployment所創建的ReplicaSet kubectl get rs ,而ReplicaSet的格式為 [DEPLOYMENT-NAME]-[RANDOM-STRING] 隨機字串的部分是使用pod-template-hash作為seed產生的,列出的ReplicaSet資訊有兩個重要的部分

    • DESIRED displays the desired number of replicas of the application, which you define when you create the Deployment. This is the desired state.
    • CURRENT displays how many replicas are currently running.
  • 再來利用 kubectl scale 指令scale Deployment變成四個ReplicaSet kubectl scale deployments/kubernetes-bootcamp --replicas=4

  • 再次取得deployments list觀察變化 kubectl get deployments

  • 取得pods的資訊 kubectl get pods -o wide

  • 觀察deployment得資訊 kubectl describe deployments/kubernetes-bootcamp

Step 2: Load Balancing

  • 首先檢查Service是否在對流量進行負載平衡,然後利用describe找出對外裸露的IP & Ports kubectl describe services/kubernetes-bootcamp

  • 將NodePort導出為環境變數 export NODE_PORT=$(kubectl get services/kubernetes-bootcamp -o go-template='{{(index .spec.ports 0).nodePort}}') echo NODE_PORT=$NODE_PORT

  • 接著利用curl多呼叫幾次API,會發現透過不同的pod response curl $(minikube ip):$NODE_PORT

Step 3: Scale Down

  • 將Service縮減為2個replicas kubectl scale deployments/kubernetes-bootcamp --replicas=2

  • 取得deployments列表確認改動成功 kubectl get deployments

  • 確認pods的數量 kubectl get pods -o wide

參考


圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言