Azure Kubernetes Service (AKS) is a fully managed container orchestration service provided by Azure. It simplifies the deployment, scaling, and operations of containerized applications by abstracting much of the underlying infrastructure. One of the key features AKS provides is the ability to automatically scale applications based on demand. This feature is pivotal in managing costs and resources efficiently in Azure.
There are two levels of scaling in AKS:
- Pod-level scaling (Horizontal Pod Autoscaler)
- Node-level scaling (Cluster Autoscaler)
Pod-level scaling (Horizontal Pod Autoscaler)
Horizontal Pod Autoscaler (HPA) is a Kubernetes feature that automatically adjusts the count of pods in a replication controller, deployment, or replica set based on observed CPU utilization. This means that you can ensure your application is only using the resources it needs and no more.
To use the HPA, you simply need to use the Kubernetes command-line tool kubectl to create an HPA resource. Here’s an example:
kubectl autoscale deployment my-app –cpu-percent=70 –min=3 –max=10
In this command, my-app
is the name of your deployment, --cpu-percent=70
sets the average CPU utilization of the pods to trigger the autoscaler, and --min=3
and --max=10
set the minimum and maximum number of pods the autoscaler can use.
Node-level scaling (Cluster Autoscaler)
The AKS Cluster Autoscaler changes the size of your cluster based on the demand of your workloads. If you have pods that are failing due to resource constraints, the autoscaler will add more nodes if allowed by the configured maximum. Conversely, if you have underutilized nodes, the autoscaler will attempt to remove them.
Enabling the cluster autoscaler involves changing the AKS cluster configuration, which can be done through the Azure CLI. Below is an example using an AKS cluster named myAKSCluster and a resource group named myResourceGroup:
az aks update \
–resource-group myResourceGroup \
–name myAKSCluster \
–enable-cluster-autoscaler \
–min-count 1 \
–max-count 3 \
–node-count 1
In this example, --enable-cluster-autoscaler
enables the autoscaler, --min-count 1
and --max-count 3
specify the minimum and maximum nodes that your cluster can scale to, and --node-count 1
indicates the initial number of nodes in your cluster.
Remember that the ability to scale automatically allows your applications to meet user demand, and also ensures that you are only paying for the resources you actually need. Both types of autoscaling – pod level and node level – offer ways for you to balance costs, performance, and resource utilization.
Conclusion
Efficient use of resources is key to running cost-effective applications in the cloud. Autoscaling capabilities of Kubernetes in AKS empower you to optimize resource utilization. Configuring autoscaling requires careful consideration of your application’s needs and behavior to choose the right minimum and maximum boundaries.
As with all aspects of cloud services, these configuration options are continuously evolving. Be sure to consult the latest Azure documentation for the most accurate and current information.
Practice Test
True or False: Azure Kubernetes Service (AKS) does not support both vertical and horizontal scaling.
- True
- False
Answer: False
Explanation: Azure Kubernetes Service (AKS) supports both vertical scaling (adjusting the capacity of existing resources) and horizontal scaling (adding or removing resources based on demand).
Which type of scaling increases the count of pod replicas in AKS?
- A) Vertical scaling
- B) Horizontal scaling
- C) Multi-node scaling
- D) None of the above
Answer: B) Horizontal scaling
Explanation: In horizontal scaling, new replicas of pods are created to handle increased demand.
Can you manually scale an AKS cluster?
- A) Yes
- B) No
- C) Only in some situations
Answer: A) Yes
Explanation: Scaling can be both manually and automatically. In manual scaling, the number of nodes is specifically set by the administrator.
Does the Azure Kubernetes Service (AKS) cluster autoscaler automatically decrease the resources during low demand?
- A) Yes
- B) No
- C) Sometimes
Answer: A) Yes
Explanation: The AKS autoscaler feature not only increases the resources during high demand but also decreases them when they are not in use.
Which of the following is not a requirement for the Kubernetes Metrics Server to auto-scale a cluster?
- A) Stable Network
- B) High performance
- C) Real-time metrics
- D) High availability
Answer: C) Real-time metrics
Explanation: The Kubernetes Metrics Server only requires resource use data, it doesn’t require real-time metrics.
Does activating the Kubernetes cluster autoscaler service incur additional costs?
- A) Yes
- B) No
- C) Only for the first month
Answer: B) No
Explanation: There are no additional costs for enabling the Kubernetes cluster autoscaler service.
True or False: AKS does not support multiple node pools.
- True
- False
Answer: False
Explanation: AKS supports the creation of multiple node pools, which allow for different types of workloads to be assigned.
Which AKS component needs to be configured to scale the application automatically?
- A) Azure Monitor
- B) Kubernetes Autoscaler
- C) Kubernetes Metrics Server
- D) Azure Logic Apps
Answer: B) Kubernetes Autoscaler
Explanation: Kubernetes Autoscaler is responsible for automatic scaling based on resource use in AKS.
What Microsoft technology works in conjunction with AKS for autoscale functionality?
- A) Microsoft PowerApps
- B) Azure Automation Account
- C) Azure Logic Apps
- D) Azure Function Apps
Answer: B) Azure Automation Account
Explanation: Azure Automation Account is used to schedule events for AKS scaling based on user-defined parameters.
True or False: Manual scale operations in AKS are instantaneous.
- True
- False
Answer: False
Explanation: Manual scale operations can take some time as new nodes have to be provisioned or old ones have to be removed.
Interview Questions
What does AKS stands for in Azure services?
AKS stands for Azure Kubernetes Service.
Is it possible to automatically scale your AKS cluster?
Yes, Azure Kubernetes Service (AKS) supports Kubernetes’ cluster autoscaler feature out of the box.
What is the function of Azure Kubernetes Service (AKS) autoscaling?
The autoscaling in Azure Kubernetes Service (AKS) adjusts the count of node instances based on the demands of the workload.
What is KEDA in the context of Azure Kubernetes?
KEDA stands for Kubernetes Event-driven Autoscaling. It is a component in AKS that enables the scaling of workloads in response to events, not just the CPU or memory pressure.
Can you manually scale your AKS cluster?
Yes, you can manually scale your Azure Kubernetes Service (AKS) using the Azure CLI or the Azure portal.
In terms of AKS, what is Azure Container Instances (ACI)?
Azure Container Instances (ACI) is a service in Azure that lets you launch containers directly without needing to manage any underlying infrastructure, helping with event-driven and burst compute scenarios in AKS.
Which command could you use to manually scale AKS using Azure CLI?
To manually scale your AKS cluster, you can use the command “az aks scale”.
How does AKS decide when to scale up?
It uses the Kubernetes Metrics Server to gather utilization data, and if the load is consistently high — above the target value — the autoscaler increases the size of the pool.
What two types of scaling does AKS support?
AKS supports two types of scaling: Manual Scaling and Autoscaling.
What is the Kubernetes Metrics Server?
The Kubernetes Metrics Server is an aggregator of resource usage data in your cluster, and it is not meant to be used for non-resource metrics.
What is the primary consideration when configuring autoscaling for AKS?
The autoscaler should be correctly configured to match the expected workload. It should neither over-provision nor under-provision resources.
How does AKS decide when to scale down?
Again, it uses the Kubernetes Metrics Server, and if the load is consistently low — below the target value — the autoscaler decreases the size of the pool.
Is it possible to enable cluster autoscaling on an existing AKS cluster?
Yes, you can enable cluster autoscaling on an existing AKS cluster using the Azure CLI or the Azure portal.
What is the function of the Kubernetes Metrics Server in AKS autoscaling?
The Kubernetes Metrics Server provides the data about the resource usage of the nodes and pods in the cluster, helping the Kubernetes cluster autoscaler to make scaling decisions.
Is there a minimum number of nodes you must have in your AKS cluster to use the autoscaling feature?
When enabling autoscaling, you designate a minimum (and maximum) number of nodes. The minimum can be as low as 1, and Azure will ensure that your cluster always has at least this number of nodes.