Daniel's Tech Blog

Cloud Computing, Cloud Native & Kubernetes

Azure Functions – Azure Kubernetes Service Advanced Networking IP address calculation

Lately I was playing around with Azure Functions especially the HTTP Trigger Function and was seeking for a good use case of a Function taking JSON input and providing JSON as output.

Looking at a certain task you need to do before you can deploy AKS with Advanced Networking enabled. I had found my use case. Before you can deploy AKS with Advanced Networking, Azure CNI plugin, you are required to calculate the required IP addresses for your nodes and pods. Beside that it is recommend taking one extra node as spare capacity for the AKS upgrade process and additional nodes for scaling, if needed, into consideration. In the end, as documented under the following link, you need two formulas based on the case to do the calculation.

-> https://docs.microsoft.com/en-us/azure/aks/configure-advanced-networking#plan-ip-addressing-for-your-cluster

Furthermore, the Azure Internal Load Balancer should be also included in the calculation when the ILB deployment targets the same subnet as for the nodes and pods.

This led me to the idea to write a Function and offer them as an API endpoint. Taking your desired configuration as input and provide you with the required IP address amount for your subnet as output. So, you know how large the subnet must be to serve your AKS cluster properly.

The API endpoint https://akscnicalc.azurewebsites.net/api/akscnicalc requires the following input.

  • nodes: Number of nodes in the AKS cluster
  • pods: Number of pods per node
  • scale: Scale out capacity (e.g. 2 nodes)
  • ilbs: Number of Azure Internal Load Balancers you would like to use in the AKS subnet and setup for your container workloads

At least the number of nodes for the input nodes is required. When only specifying the input nodes the other inputs have the following default values.

  • pods: 30
  • scale: 0
  • ilbs: 0

Here are some examples how you can call the API endpoint from bash, PowerShell or through your web browser.

bash:

curl -X POST https://akscnicalc.azurewebsites.net/api/akscnicalc --data-raw '{"nodes": 3, "pods": 30, "scale": 2, "ilbs": 3}'

{
  "nodes": 3,
  "pods": 30,
  "scale": 2,
  "ilbs": 3,
  "ipaddresses": 189
}

PowerShell:

$body= @{
    nodes=3
    pods=30
    scale=2
    ilbs=3
}
(Invoke-WebRequest 'https://akscnicalc.azurewebsites.net/api/akscnicalc' -Body ($body|ConvertTo-Json) -Method 'POST').Content
{
  "nodes": 3,
  "pods": 30,
  "scale": 2,
  "ilbs": 3,
  "ipaddresses": 189
}

Web browser:

https://akscnicalc.azurewebsites.net/api/akscnicalc?nodes=3&pods=30&scale=2&ilbs=3

akscnicalc01

Providing a value above the AKS limits results in the following error messages.

-> https://docs.microsoft.com/en-us/azure/aks/container-service-quotas

Input value nodes is null or 0:

curl -X POST https://akscnicalc.azurewebsites.net/api/akscnicalc --data-raw ''
Please pass 'nodes' on the query string or in the request body at least with a number greater than 0.

Input value nodes is above the AKS node limit:

curl -X POST https://akscnicalc.azurewebsites.net/api/akscnicalc --data-raw '{"nodes": 90, "pods": 30, "scale": 20, "ilbs": 0}'
Node number is higher than the supported limit of 100 nodes per cluster.

Input value pods is above the AKS pod limit:

curl -X POST https://akscnicalc.azurewebsites.net/api/akscnicalc --data-raw '{"nodes": 90, "pods": 150, "scale": 10, "ilbs": 0}'
Pod number is higher than the supported limit of 110 per node.

For all of you that would like to run the Azure Function as FaaS on Kubernetes itself. You find the container image on Docker Hub.

-> https://hub.docker.com/r/neumanndaniel/akscnicalc/tags/

The Function provides the following log output depending what inputs were given.

Log output for an AKS cluster with 3 nodes, 30 pods, 2 nodes as scaling option and 2 Azure ILBs.

Azure Function:

curl -X POST https://akscnicalc.azurewebsites.net/api/akscnicalc --data-raw '{"nodes": 3, "pods": 30, "scale": 2, "ilbs": 2}'

akscnicalc02

FaaS on Kubernetes:

curl -X POST http://40.113.69.17/api/aksCniCalc --data-raw '{"nodes": 3, "pods": 30, "scale": 2, "ilbs": 2}'
11/26/2018 12:44:52 [INF]: C# HTTP trigger function processed a request.
11/26/2018 12:44:52 [INF]: Processed AKS cluster CNI IP address calculation for '3' node(s), '30' pod(s) with a scaling option of '2' node(s) and '2' Azure Internal Load Balancer(s) successfully. Result: '188' IP addresses required.

Log output for an AKS cluster with 20 nodes, 110 pods, 0 nodes as scaling option and 0 Azure ILBs.

Azure Function:

curl -X POST https://akscnicalc.azurewebsites.net/api/akscnicalc --data-raw '{"nodes": 20, "pods": 110, "scale": 0, "ilbs": 0}'

akscnicalc03

FaaS on Kubernetes:

curl -X POST http://40.113.69.17/api/aksCniCalc --data-raw '{"nodes": 20, "pods": 110, "scale": 0, "ilbs": 0}'
11/26/2018 12:44:55 [INF]: C# HTTP trigger function processed a request.
11/26/2018 12:44:55 [INF]: Processed AKS cluster CNI IP address calculation for '20' node(s), '110' pod(s) with a scaling option of '0' node(s) and '0' Azure Internal Load Balancer(s) successfully. Result: '2331' IP addresses required.

The code for both implementations is available on my GitHub repository.

-> https://github.com/neumanndaniel/serverless/tree/master/AKS-CNI-Calc

WordPress Cookie Notice by Real Cookie Banner