Back to Blog

Optimal Subnet Sizing for Azure Kubernetes Service (AKS): A Comprehensive Guide

(1 rating)
Stunning aerial beach view with blue umbrellas and clear turquoise waters.
Stunning aerial beach view with blue umbrellas and clear turquoise waters. • Photo by Francesco Ungaro on Pexels

Introduction

Azure Kubernetes Service (AKS) is a managed container orchestration service that allows you to deploy, manage, and scale containerized applications. When deploying an AKS cluster, one of the critical decisions you need to make is the size of the subnet. The subnet size determines the number of IP addresses available for your cluster, which in turn affects the scalability and performance of your applications. In this post, we will delve into the factors to consider when sizing subnets for AKS, along with best practices and practical examples to help you get it right.

Factors to Consider

When sizing a subnet for AKS, there are several factors to consider:

  • Number of nodes: The number of nodes in your cluster determines the number of IP addresses required. Each node requires a unique IP address.
  • Pod density: The number of pods per node affects the number of IP addresses required. Each pod requires a unique IP address.
  • Service exposure: Exposed services require additional IP addresses for load balancers and ingress controllers.
  • Future growth: Consider the expected growth of your cluster and applications when sizing the subnet.

Calculating Subnet Size

To calculate the subnet size, you can use the following formula:

Subnet size = (number of nodes x pod density) + (number of exposed services x 2) + (future growth buffer)

For example, if you expect to have 10 nodes with a pod density of 10 pods per node, and 5 exposed services, your subnet size would be:

Subnet size = (10 x 10) + (5 x 2) + 10% buffer = 100 + 10 + 10 = 120

Subnet Size Considerations

When choosing a subnet size, consider the following:

  • CIDR notation: Azure supports CIDR notation for subnet sizing. A larger CIDR block provides more IP addresses, but may also increase routing complexity.
  • Subnet prefix: The subnet prefix determines the number of available IP addresses. A /24 prefix provides 256 IP addresses, while a /16 prefix provides 65,536 IP addresses.

Example Subnet Configuration

Here is an example of a subnet configuration in Azure:

1az network vnet subnet create \
2  --resource-group myResourceGroup \
3  --vnet-name myVnet \
4  --name mySubnet \
5  --address-prefixes 10.0.0.0/24

This example creates a subnet with a /24 prefix, providing 256 available IP addresses.

AKS Cluster Configuration

When creating an AKS cluster, you can specify the subnet size using the --subnet parameter:

1az aks create \
2  --resource-group myResourceGroup \
3  --name myAKSCluster \
4  --subnet mySubnet

Pod Networking

AKS uses a pod networking model, where each pod receives a unique IP address. The pod IP address range is determined by the subnet size. You can configure pod networking using the --pod-cidr parameter:

1az aks create \
2  --resource-group myResourceGroup \
3  --name myAKSCluster \
4  --subnet mySubnet \
5  --pod-cidr 10.244.0.0/16

This example configures the pod IP address range to 10.244.0.0/16, providing 65,536 available IP addresses for pods.

Service Exposure

When exposing services, you need to consider the additional IP addresses required for load balancers and ingress controllers. You can use the --service-cidr parameter to configure the service IP address range:

1az aks create \
2  --resource-group myResourceGroup \
3  --name myAKSCluster \
4  --subnet mySubnet \
5  --pod-cidr 10.244.0.0/16 \
6  --service-cidr 10.0.0.0/24

This example configures the service IP address range to 10.0.0.0/24, providing 256 available IP addresses for services.

Common Pitfalls

When sizing subnets for AKS, there are several common pitfalls to avoid:

  • Insufficient IP addresses: Failing to provide enough IP addresses can lead to pod scheduling failures and service exposure issues.
  • Inadequate subnet prefix: Choosing a subnet prefix that is too small can limit the number of available IP addresses and increase routing complexity.
  • Inconsistent pod networking: Failing to configure pod networking consistently can lead to connectivity issues and service exposure problems.

Best Practices

To ensure optimal subnet sizing for AKS, follow these best practices:

  • Plan for future growth: Consider the expected growth of your cluster and applications when sizing the subnet.
  • Use a consistent subnet prefix: Use a consistent subnet prefix throughout your Azure environment to simplify routing and reduce complexity.
  • Monitor IP address usage: Regularly monitor IP address usage to ensure that you have enough available IP addresses for your cluster and applications.

Conclusion

Optimal subnet sizing is critical for the performance and security of AKS clusters. By considering factors such as node count, pod density, service exposure, and future growth, you can determine the optimal subnet size for your AKS cluster. Remember to avoid common pitfalls, such as insufficient IP addresses and inadequate subnet prefixes, and follow best practices, such as planning for future growth and using a consistent subnet prefix. With careful planning and configuration, you can ensure that your AKS cluster has the optimal subnet size for your applications and workloads.

Comments

Leave a Comment

Was this article helpful?

Rate this article

4.9 out of 5 based on 1 rating