Tutorial / Cram Notes

Azure Kubernetes Service (AKS) is a managed container orchestration service provided by Microsoft Azure that simplifies the deployment, management, and scaling of containerized applications. In the context of the AZ-104 Microsoft Azure Administrator exam, understanding how to configure scaling within AKS is an essential skill.

Horizontal Pod Autoscaling

AKS supports horizontal pod autoscaling (HPA) that automatically adjusts the number of pods in a deployment or replica set in response to CPU utilization or other select metrics:

  1. Enable Metrics Server:

    First, ensure that the metrics server, which provides resource metrics for pods and nodes, is deployed on your AKS cluster. It is generally installed by default in AKS for clusters created after March 2019.

  2. Configure HPA:

    Horizontal Pod Autoscaler uses the Kubernetes API to scale applications. You can set up an HPA using the kubectl autoscale command or by creating a YAML configuration for the HPA object.

    Example HPA YAML:

    apiVersion: autoscaling/v1
    kind: HorizontalPodAutoscaler
    metadata:
    name: myapp-hpa
    namespace: mynamespace
    spec:
    maxReplicas: 10
    minReplicas: 2
    scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: myapp-deployment
    targetCPUUtilizationPercentage: 50

    This HPA configuration would scale the deployment myapp-deployment between 2 to 10 replicas, aiming to maintain an average CPU utilization across all replicas of 50%.

  3. Apply the HPA:

    You can apply the HPA to your cluster using the kubectl apply -f command:

    kubectl apply -f hpa.yaml

Vertical Pod Autoscaling

Vertical Pod Autoscaling (VPA) adjusts the CPU and memory reservations for pods in response to load. However, it’s not directly supported in AKS as of the knowledge cutoff in 2023 but can be manually installed and configured.

Cluster Autoscaler

For an AKS cluster to automatically adjust the number of nodes, the cluster autoscaler can be enabled:

  1. Enable Cluster Autoscaler:

    When creating a new AKS cluster or updating an existing one, you can enable the cluster autoscaler with the Azure CLI or ARM templates. For an existing cluster, the command might look like:

    az aks update \
    --resource-group myResourceGroup \
    --name myAKSCluster \
    --enable-cluster-autoscaler \
    --min-count 1 \
    --max-count 3

    This sets the minimum number of nodes to 1 and the maximum to 3.

  2. Tune Autoscaler Parameters:

    Parameters such as scan-interval, scale-down-delay-after-add, and others can be adjusted based on the needs of your workload by using the --cluster-autoscaler-profile parameter when creating or updating a cluster.

Manual Scaling

  1. Scale Pods Manually:

    To manually scale the number of pods in a deployment:

    kubectl scale --replicas=5 deployment/myapp-deployment

    This command scales the myapp-deployment to 5 replicas.

  2. Scale Nodes Manually:

    To manually scale the number of nodes in the node pool:

    az aks nodepool scale \
    --resource-group myResourceGroup \
    --cluster-name myAKSCluster \
    --name mynodepool \
    --node-count 3

    This command changes the count of nodes in the node pool mynodepool to 3.

Considerations for Scaling

  • Cost: Scaling out (horizontal) increases the number of VMs and can quickly elevate costs.
  • Performance: Choose the right metrics for autoscaling to ensure performance isn’t negatively impacted.
  • Limits: Be aware of subscription and service limits for AKS resources to avoid errors during scaling operations.

Understanding and configuring scaling options in AKS are important for managing the performance and costs associated with your applications and are considered key knowledge for an Azure Administrator as outlined within the AZ-104 exam objectives.

Practice Test with Explanation

True or False: In Azure Kubernetes Service (AKS), you can only manually scale the number of nodes in a node pool.

  • A) True
  • B) False

Answer: B) False

Explanation: In AKS, you can either manually scale the number of nodes in a node pool or configure the cluster to automatically scale nodes through the Horizontal Pod Autoscaler or the cluster autoscaler feature.

What is the primary purpose of the Horizontal Pod Autoscaler (HPA) in AKS?

  • A) To adjust the number of nodes in the cluster
  • B) To adjust the number of pods in a deployment based on CPU utilization or other select metrics
  • C) To manage the version of Kubernetes in the cluster
  • D) To schedule pods on nodes in the cluster

Answer: B) To adjust the number of pods in a deployment based on CPU utilization or other select metrics

Explanation: The Horizontal Pod Autoscaler automatically scales the number of pods in a deployment or stateful set based on observed CPU utilization or other selected metrics provided by custom metrics support.

True or False: AKS supports manual scaling only at the pod level, not at the node level.

  • A) True
  • B) False

Answer: B) False

Explanation: AKS supports manual scaling at both the pod level and the node level. You can adjust the number of pods in a deployment as well as the number of nodes in the node pool.

Which of the following metrics can trigger automatic scaling in AKS?

  • A) CPU utilization
  • B) Memory utilization
  • C) Custom metrics from Azure Monitor
  • D) All of the above

Answer: D) All of the above

Explanation: AKS cluster autoscaler can automatically scale based on metrics like CPU utilization, memory utilization, or any other custom metrics you configure from Azure Monitor.

Which AKS feature allows you to scale node count based on the demands of the workloads?

  • A) Manual scaling
  • B) Horizontal Pod Autoscaler (HPA)
  • C) Vertical Pod Autoscaler (VPA)
  • D) Cluster Autoscaler

Answer: D) Cluster Autoscaler

Explanation: The cluster autoscaler feature in AKS enables the automatic adjustment of the number of nodes in the cluster based on the resource demands of the workloads.

True or False: You can configure multiple node pools in AKS for various workloads that require different VM sizes or operating systems.

  • A) True
  • B) False

Answer: A) True

Explanation: AKS supports the creation of multiple node pools, allowing you to run various workloads that require different VM sizes or operating systems within the same cluster.

When scaling down a node in AKS, what does the cluster autoscaler guarantee?

  • A) It guarantees that no pods will be disrupted.
  • B) It guarantees that only pods with lower priority will be disrupted.
  • C) It evicts pods if necessary, following a certain eviction order.
  • D) All nodes will scale down simultaneously.

Answer: C) It evicts pods if necessary, following a certain eviction order.

Explanation: The cluster autoscaler in AKS follows a specific order for evicting pods when scaling down a node, trying to minimize disruptions but not guaranteeing that no disruptions will occur.

When configuring AKS auto-scaling, what is a common best practice?

  • A) Set max nodes to the maximum possible limit for the cluster.
  • B) Provide enough buffer in the min and max node count to handle workload spikes.
  • C) Only scale based on CPU utilization, ignoring other metrics.
  • D) Disable the Horizontal Pod Autoscaler.

Answer: B) Provide enough buffer in the min and max node count to handle workload spikes.

Explanation: When configuring auto-scaling, it’s a best practice to provide enough buffer in the minimum and maximum node counts to ensure the cluster can handle unexpected workload spikes without hitting resource limits.

True or False: The Vertical Pod Autoscaler (VPA) in AKS recommends and sets resource limits for pods automatically.

  • A) True
  • B) False

Answer: A) True

Explanation: While VPA is not a native AKS feature, it is a Kubernetes feature that can be used in AKS to automatically adjust the CPU and memory reservations and limits for pods.

Which command can be used to manually scale the number of nodes in an AKS cluster using Azure CLI?

  • A) az aks scale
  • B) az aks autoscale
  • C) az aks set-scale
  • D) az aks update-scale

Answer: A) az aks scale

Explanation: The ‘az aks scale’ command is used to manually adjust the number of nodes in an AKS cluster node pool using the Azure CLI.

True or False: When enabling cluster autoscaler in AKS, you cannot specify the minimum and maximum number of nodes.

  • A) True
  • B) False

Answer: B) False

Explanation: When you enable the cluster autoscaler in AKS, you must specify the minimum and maximum number of nodes for the autoscaler to operate within.

If an AKS node pool is configured with virtual machine scale sets (VMSS), how does this affect scaling operations?

  • A) VMSS is required for manual scaling only.
  • B) VMSS does not support autoscaling; a different scaling method must be used.
  • C) VMSS enables more efficient and faster scaling operations in AKS.
  • D) VMSS negatively impacts scaling performance due to increased complexity.

Answer: C) VMSS enables more efficient and faster scaling operations in AKS.

Explanation: When node pools in AKS are configured with virtual machine scale sets (VMSS), it allows for more efficient and faster scaling operations due to VMSS capabilities to add or remove VM instances as needed.

Interview Questions

What is AKS, and why is it important to scale AKS clusters?

AKS is a managed Kubernetes service that makes it easy to deploy, scale, and manage containerized applications. Scaling AKS clusters is important to ensure that your application can handle changes in demand.

What are the different scaling options available in AKS?

The different scaling options available in AKS include scaling the number of nodes, adding more capacity to your nodes, and scaling your application horizontally.

How can you scale the number of nodes in your AKS cluster?

To scale the number of nodes in your AKS cluster, you can use the Azure portal or Azure CLI. Simply select your AKS cluster, go to the “Scale” tab, and adjust the number of nodes as needed. You can also use the Azure CLI by running the “az aks scale” command and specifying the number of nodes you want to add or remove.

How can you add more capacity to your nodes in AKS?

To add more capacity to your nodes in AKS, you can scale up your nodes or add more nodes with larger resource configurations. You can use the Azure portal or Azure CLI to perform these actions.

How can you scale up your nodes in AKS?

To scale up your nodes in AKS, you can use the Azure portal or Azure CLI. Simply select your AKS cluster, go to the “Scale” tab, and select a larger node size. You can also use the Azure CLI by running the “az aks nodepool update” command and specifying the new node size.

How can you add more nodes with larger resource configurations in AKS?

To add more nodes with larger resource configurations in AKS, you can use the Azure portal or Azure CLI. Simply select your AKS cluster, go to the “Node pools” tab, and add a new node pool with the larger resource configuration. You can also use the Azure CLI by running the “az aks nodepool add” command and specifying the new node pool configuration.

What is horizontal pod autoscaling, and how can you use it in AKS?

Horizontal pod autoscaling is a feature in Kubernetes that automatically scales the number of replicas of a deployment based on CPU usage or other metrics. You can use horizontal pod autoscaling in AKS to automatically scale your application based on demand.

How can you use kubectl to scale your application horizontally in AKS?

To scale your application horizontally in AKS using kubectl, you can run the “kubectl scale” command and specify the number of replicas you want to add.

What is a node pool in AKS, and how can you add or remove node pools?

A node pool in AKS is a set of nodes with the same configuration. You can add or remove node pools by using the Azure portal or Azure CLI.

How can you check the status of scaling operations in AKS?

You can use the Azure portal or Azure CLI to check the status of scaling operations in AKS. In the Azure portal, you can view the “Activity log” to see the status of scaling operations. In the Azure CLI, you can run the “az aks show” command to view the current status of your AKS cluster.

0 0 votes
Article Rating
Subscribe
Notify of
guest
12 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Mario Portillo
5 months ago

Can anyone explain how to configure node autoscaling for AKS?

André Renken
2 years ago

Do you know the best practices for scaling AKS clusters?

Nicolas Taylor
1 year ago

Great post, very informative!

Cristóbal Blanco
1 year ago

Has anyone faced any issues while enabling virtual nodes for AKS?

Onni Couri
1 year ago

Thanks for the detailed explanation on AKS scaling!

Scarlett Felix
1 year ago

How does the cluster autoscaler handle scale-down scenarios?

Anthony Perrin
1 year ago

I don’t think this method is reliable for production environments.

Zachary Zhang
1 year ago

Can you mix different VM sizes in a single AKS cluster?

12
0
Would love your thoughts, please comment.x
()
x