- Published on
Azure Kubernetes Service cost analysis (preview)
- Authors
- Name
- Alexander Arana Escobedo
Finally, we have an easy add-on that we can enable on our AKS clusters to get a breakdown of costs between the different namespaces and more. This can be viewed through cost analysis.
Before proceeding, make sure that your cluster is not on the free tier. It needs to be Standard or Premium.
Below is the code to update your cluster with the cost analysis add-on. If you want the full documentation and instructions on how to enable the add-on when creating the cluster, click here.
Step 1: Updating AKS cluster with cost analysis add-on
#Variables.
$clusterName = ""
$clusterResourceGroup = ""
$subscriptionName = ""
#If you need to update the extension version.
az extension update --name aks-preview
#Register the 'ClusterCostAnalysis' feature flag.
az feature register --namespace "Microsoft.ContainerService" --name "ClusterCostAnalysis"
#Verify that the 'ClusterCostAnalysis' feature flag is registered.
#Took me 10-15 minutes before it was done!
az feature show --namespace "Microsoft.ContainerService" --name "ClusterCostAnalysis"
#When the status reflects 'Registered', refresh the registration.
az provider register --namespace Microsoft.ContainerService
#Set the Azure CLI context to the specified subscription.
az account set --name $subscriptionName
#Enable cost analysis on the AKS cluster.
az aks update --name $clusterName --resource-group $clusterResourceGroup --enable-cost-analysis
Step 2: View Kubernetes costs (Preview)
You can view your Kubernetes costs in two different ways through the Cost Analysis on the subscription or Cost Management page.
There's no need for me to write any instructions as Microsoft has great documentation around this.
I hope this guide helps you out! If you have any questions, don’t hesitate to reach out.
Alexander Arana.E