(DEPRECATED) Scale Kubernetes pods and Kubernetes infrastructure


For the updated version this tutorial that uses Azure Kubernetes Service, see Tutorial: Scale applications in Azure Kubernetes Service (AKS).


The Azure Container Service (ACS) is being deprecated. No new features or functionality are being added to ACS. All of the APIs, portal experience, CLI commands and documentation are marked as deprecated.

In 2017, we introduced Azure Kubernetes Service (AKS) for simplifying Kubernetes management, deployment, and operations. If you use the Kubernetes orchestrator, please migrate to AKS by January 31, 2020. To get started, see migrate to Azure Kubernetes Service.

For more information, see the Azure Container Service deprecation announcement on Azure.com.

If you've been following the tutorials, you have a working Kubernetes cluster in Azure Container Service and you deployed the Azure Voting app.

In this tutorial, part five of seven, you scale out the pods in the app and try pod autoscaling. You also learn how to scale the number of Azure VM agent nodes to change the cluster's capacity for hosting workloads. Tasks completed include:

  • Manually scaling Kubernetes pods
  • Configuring Autoscale pods running the app front end
  • Scale the Kubernetes Azure agent nodes

In subsequent tutorials, the Azure Vote application is updated, and Log Analytics is configured to monitor the Kubernetes cluster.

Before you begin

In previous tutorials, an application was packaged into a container image, this image uploaded to Azure Container Registry, and a Kubernetes cluster created. The application was then run on the Kubernetes cluster.

If you have not done these steps, and would like to follow along, return to the Tutorial 1 – Create container images.

Manually scale pods

Thus far, the Azure Vote front-end and Redis instance have been deployed, each with a single replica. To verify, run the kubectl get command.

kubectl get pods


NAME                               READY     STATUS    RESTARTS   AGE
azure-vote-back-2549686872-4d2r5   1/1       Running   0          31m
azure-vote-front-848767080-tf34m   1/1       Running   0          31m

Manually change the number of pods in the azure-vote-front deployment using the kubectl scale command. This example increases the number to 5.

kubectl scale --replicas=5 deployment/azure-vote-front

Run kubectl get pods to verify that Kubernetes is creating the pods. After a minute or so, the additional pods are running:

kubectl get pods


NAME                                READY     STATUS    RESTARTS   AGE
azure-vote-back-2606967446-nmpcf    1/1       Running   0          15m
azure-vote-front-3309479140-2hfh0   1/1       Running   0          3m
azure-vote-front-3309479140-bzt05   1/1       Running   0          3m
azure-vote-front-3309479140-fvcvm   1/1       Running   0          3m
azure-vote-front-3309479140-hrbf2   1/1       Running   0          15m
azure-vote-front-3309479140-qphz8   1/1       Running   0          3m

Autoscale pods

Kubernetes supports horizontal pod autoscaling to adjust the number of pods in a deployment depending on CPU utilization or other select metrics.

To use the autoscaler, your pods must have CPU requests and limits defined. In the azure-vote-front deployment, the front-end container requests 0.25 CPU, with a limit of 0.5 CPU. The settings look like:

     cpu: 250m
     cpu: 500m

The following example uses the kubectl autoscale command to autoscale the number of pods in the azure-vote-front deployment. Here, if CPU utilization exceeds 50%, the autoscaler increases the pods to a maximum of 10.

kubectl autoscale deployment azure-vote-front --cpu-percent=50 --min=3 --max=10

To see the status of the autoscaler, run the following command:

kubectl get hpa


NAME               REFERENCE                     TARGETS    MINPODS   MAXPODS   REPLICAS   AGE
azure-vote-front   Deployment/azure-vote-front   0% / 50%   3         10        3          2m

After a few minutes, with minimal load on the Azure Vote app, the number of pod replicas decreases automatically to 3.

Scale the agents

If you created your Kubernetes cluster using default commands in the previous tutorial, it has three agent nodes. You can adjust the number of agents manually if you plan more or fewer container workloads on your cluster. Use the az acs scale command, and specify the number of agents with the --new-agent-count parameter.

The following example increases the number of agent nodes to 4 in the Kubernetes cluster named myK8sCluster. The command takes a couple of minutes to complete.

az acs scale --resource-group=myResourceGroup --name=myK8SCluster --new-agent-count 4

The command output shows the number of agent nodes in the value of agentPoolProfiles:count:

  "agentPoolProfiles": [
      "count": 4,
      "dnsPrefix": "myK8SCluster-myK8SCluster-e44f25-k8s-agents",
      "fqdn": "",
      "name": "agentpools",
      "vmSize": "Standard_D2_v2"

Next steps

In this tutorial, you used different scaling features in your Kubernetes cluster. Tasks covered included:

  • Manually scaling Kubernetes pods
  • Configuring Autoscale pods running the app front end
  • Scale the Kubernetes Azure agent nodes

Advance to the next tutorial to learn about updating application in Kubernetes.