# How to start and stop Azure Kubernetes clusters

# Save costs by stopping an Azure Kubernetes Service cluster

Running multiple containers in an Azure Kubernetes Service cluster (opens new window) can be expensive and might not be necessary all the time, if your application isn't used continuously. To save costs, you could scale down your user node pools to zero, but your system pool still needs to run. Now, you can stop your entire Azure Kubernetes Service cluster to save costs. When it is stopped, the state of your objects and cluster configuration remains saved, allowing you to restore everything when you start the cluster again.

In this post, we'll stop and start an Azure Kubernetes Service cluster.

# Prerequisites

If you want to follow along, you'll need the following:

# Stop and start an Azure Kubernetes Service cluster

Let's use the Azure CLI to stop and start a Kubernetes Service Cluster. We'll start with an existing cluster that is currently in a running state.

(Feature in registering state)

  1. Open a command prompt
  2. To start and stop an AKS cluster, we need the aks-preview extension for the Azure CLI. Run the following commands to install it and to make sure that you have the latest version:
# Install the aks-preview extension
az extension add --name aks-preview

# Update the extension to make sure you have the latest version installed
az extension update --name aks-preview
1
2
3
4
5
  1. We also need to enable the StartStopPreview feature flag on your subscription with this command:
az feature register --namespace "Microsoft.ContainerService" --name "StartStopPreview"
1
  1. Wait until the feature is registered. You can check if it is with this command:
az feature list -o table --query "[?contains(name, 'Microsoft.ContainerService/StartStopPreview')].{Name:name,State:properties.state}"
1

(Feature in registering state)

  1. When the feature is registered, refresh the registration for the Microsoft.ContainerService resource provider with this command:
az provider register --namespace Microsoft.ContainerService
1
  1. Alright, let's stop our ASK cluster. You can stop a cluster with this command, where you fill in the name of your AKS cluster and the resource group of the cluster:
az aks stop --name myAKSCluster --resource-group myResourceGroup
1
  1. When the cluster is stopped, you can check to see if it is, by running the following command:
az aks show --name myAKSCluster --resource-group myResourceGroup
1

In the JSON that follows, you can see the status of the cluster by looking at the powerState, which will show Stopped.

(Stopped state)

  1. You can easily start the cluster again with the this command:
az aks start --name myAKSCluster --resource-group myResourceGroup
1

# Conclusion

Stopping an Azure Kubernetes Service cluster (opens new window) is a great way to save money. You can easily start and stop AKS with an Azure CLI (opens new window) command, which you can, for instance, automate (opens new window) to stop when the service isn't used and start during business hours. Go and check it out!