Azure Kubernetes level automatic expansion Pod

When we deploy applications to AKS in the form of a pod of external services, in order to ensure that users can get a good experience, we need to focus on the following two situations:

  • POD is unknown because the original hang, resulting in service unavailable
  • When a large number of user access, Pod in the case of high load applications can support our

For high availability Pod AKS we can use the controller to ensure that the deployment Pod can continue to provide services, but when faced with large numbers of users to access, we need to expand our resources to meet business needs.
Previous article to introduce the manually extend the pod to meet business expansion needs, but I believe we have realized that if we human monitoring pods, manually adjust the copy then the workload will be enormous, but it has been a corresponding kubernetes mechanisms to deal with the. This is the level we want to introduce today's automatic expansion of POD (HPA)
HPA stands for Horizontal Pod Autoscaler workflow controller

HPA works as follows:

  • HPA create resource objects associated resources corresponding to the Deployment e.g., setting the target CPU utilization threshold, the maximum, minimum number of replica.
    Premise: pod must be set resource limits, parameter request, HPA will work.
  • HPA controller every 15 seconds (set by the controller manager -horizontal-pod-autoscaler-sync-period parameter settings, default 15s) acquired by observing the resource usage information metrics values
  • The controller will obtain HPA and HPA resource use information set value comparison, calculate the number of copies to be adjusted
  • The calculated number of copies are adjusted such that a single CPU usage possible approximation POD expectations, but can not take care to set minimum and maximum values.
  • 3, 4 or more cycles

Having said that, let's look at how to configure the HPA:
Before configuring the HPA, we need to understand the configuration of Node node
checks and configuration resource limit
use kubectl get nodes command to check node information (node name)
Azure Kubernetes level automatic expansion Pod
using the command kubectl describe nodes NODE_NAME confirm the status of the configuration of Node resources, because we have not previously configured resource quata, so we need to set up resource limitations:
Azure Kubernetes level automatic expansion Pod
open yaml file we created earlier, modify resources configuration in which the CPU configuration Container uses only one CPU unit, Request 0.5 CPU units limit:
Azure Kubernetes level automatic expansion Pod
after completion of editing using kubectl apply -f FILE_NAME POD corresponds to redeploy
Azure Kubernetes level automatic expansion Pod

Automatically set the horizontal extension HPA
using the command kubectl autoscale deployment nginx - cpu-percent = 1 --min = 1 --max = 10 is automatically set to CPU-percent expansion is set to 1%, and the minimum is set to the number of replica 1, maximum number of replica set to 10.
Azure Kubernetes level automatic expansion Pod

After the configuration we use webbench to stress test our deployment NGINX website:
Azure Kubernetes level automatic expansion Pod
using the command kubectl get hpa observe the state level auto expansion, please note that Target has two numbers, is the Current / Target CPU usage
Azure Kubernetes level automatic expansion Pod
using the command kubectl get deployment observation whether to increase the number of deployment
Azure Kubernetes level automatic expansion Pod
using the command kubectl get pod observe whether the increase in the number of pod, and pay attention to the state, if> 1 indicates the level of automatic expansion (hpa) has been successfully set up and take effect
Azure Kubernetes level automatic expansion Pod

Clear resource
test is completed, we can use kubect delete -f FILE_NAME to delete the corresponding resource deployment:
Azure Kubernetes level automatic expansion Pod
Use kubectl delete hpa nginx to delete hpa resources:
Azure Kubernetes level automatic expansion Pod

Guess you like

Origin blog.51cto.com/wuyvzhang/2465776