TIP
🔥 Checkout the Azure Developer page at azure.com/developer (opens new window).
💡 Learn more : Azure Kubernetes Service overview (opens new window).
📺 Watch the video : How to start and stop Azure Kubernetes clusters (opens new window).
# 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:
- An Azure subscription (If you don't have an Azure subscription, create a free account (opens new window) before you begin)
- An Azure Kubernetes Cluster. Create one using this quickstart (opens new window)
- The Azure CLI (opens new window). You can download it for Windows, Linux or Mac (opens new window)
# 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)
- Open a command prompt
- 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
2
3
4
5
- We also need to enable the StartStopPreview feature flag on your subscription with this command:
az feature register --namespace "Microsoft.ContainerService" --name "StartStopPreview"
- 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}"
(Feature in registering state)
- When the feature is registered, refresh the registration for the Microsoft.ContainerService resource provider with this command:
az provider register --namespace Microsoft.ContainerService
- 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
- 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
In the JSON that follows, you can see the status of the cluster by looking at the powerState, which will show Stopped.
(Stopped state)
- You can easily start the cluster again with the this command:
az aks start --name myAKSCluster --resource-group myResourceGroup
# 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!