I’ve been trying for some time to run the cheapest single-node Kubernetes cluster I could on Azure Kubernetes Service (AKS). My target is to run it for a month at $70 (AUD) or below, but it takes some investigation to determine how to do this.
I’m using the Azure CLI and, prior to optimising for cost, the command to bring a cluster up looks like this;
az aks create -n myCluster
This will bring up a cluster with default settings that will cost much more than my target, so over the next few sections I’ll add to this command such that the resulting cluster is much cheaper. All prices are $AUD and the region is Australia East.
If you don’t care for the why, see the result here.
Node count and size
By default, the cluster is going to have 3x Standard_DS2_v2, which will cost us ~$844.929/month. We’ll drop this to a single node and smaller size VM. AKS docs note that every AKS cluster will have at minimum one system node pool, and, that system node pools require a VM SKU of at least 2 vCPUs and 4GB memory. The cheapest VM at that configuration is the Standard_B2s @ ~$52.921/month.
We can set this using the the following parameters;
--node-count 1 --node-vm-size Standard_B2s
AKS uses a Load Balancer and by default the Standard sku @ ~$30/month will be selected. The Basic sku is free, but the Load Balancer sku cannot be changed once the cluster has been created, so we must set it at time of creation.
Node disk size
Disk size defaults to 100GB which for this VM is a Premium SSD p10 @ ~$27/month. Minimum disk size is 30 so we’ll choose the 32GB p4 @ $7.25/month.
The cheapest cluster
az aks create -n myCluster \
--node-count 1 \
--node-vm-size Standard_B2s \
--load-balancer-sku basic \
Running these settings for a month comes in at ~$66AUD.
There were other avenues I investigated to decrease the cost that, at the time of writing, were not feasible. I’ll take a look at these now.
Spot VMs allow access to excess cloud capacity at a reduced cost, but the access to the VM is not guaranteed and eviction policies mean the VM may be deallocated if Azure needs that capacity back.
You cannot create a cluster with Spot Node pool and instead it must be added to the cluster afterwards. To add an additional node pool, the cluster must support multiple node pools. Both multiple node pools and Spot node pools require the Standard SKU load balancer and therefore would increase the price $30/month.
Standard SSDs are cheaper than Premium SSDs. Although the Azure Pricing Calculator lets you choose the Managed OS Disk Tier for your nodepool, setting a disk type on an agentpool is not currently supported and for a Standard_B2s VM,
aks create selects a Premium SSD. See the Github issue and subsequent Azure Feedback forum entry.