How to Start and Stop an AKS Cluster

Introduction

Azure Kubernetes Service (AKS) is a managed Kubernetes service that simplifies the deployment, management, and scaling of containerized applications. While AKS offers significant scalability and performance benefits, running an AKS cluster 24/7 can result in unnecessary costs, especially during off-peak hours or when the cluster is not in use.

To address this, Azure provides the ability to start and stop AKS clusters, enabling cost savings. This article will guide you through the process of starting and stopping an AKS cluster using the Azure CLI, along with insights into key features, advantages, disadvantages, best practices, and troubleshooting steps.


Why Start and Stop an AKS Cluster?

Stopping an AKS cluster shuts down the cluster’s resources, including its virtual machines (VMs), while retaining the configuration and state. This allows you to save costs without losing data or needing to reconfigure the cluster.


Prerequisites

  1. An active Azure account.
  2. An existing Azure Kubernetes Service (AKS) cluster.
  3. Azure CLI installed on your local machine or access to the Azure Cloud Shell.

How to Start and Stop an AKS Cluster

Step 1: Install and Update the AKS Preview Extension

To use the start and stop functionality, you need the AKS Preview Extension in the Azure CLI.

  1. Install the AKS Preview Extension:
    az extension add --name aks-preview
  2. Update the Extension to the Latest Version:
    az extension update --name aks-preview

Step 2: Register the Start/Stop Preview Feature

The start and stop functionality is part of the preview feature in AKS.

  1. Register the Start/Stop Preview Feature:
    az feature register --namespace "Microsoft.ContainerService" --name "StartStopPreview"

    This registration process may take a few minutes.

  2. Verify the Feature Registration:
    az feature list -o table --query "[?contains(name,'Microsoft.ContainerService/StartStopPreview')].{Name:name, State:properties.state}"
  3. Refresh the Container Resource Provider:
    az provider register --namespace Microsoft.ContainerService 

Step 3: Stop the AKS Cluster

Use the following command to stop your AKS cluster:

az aks stop --name YOUR_CLUSTER_NAME --resource-group YOUR_RESOURCE_GROUP
  • Replace YOUR_CLUSTER_NAME with the name of your AKS cluster.
  • Replace YOUR_RESOURCE_GROUP with the name of the resource group that contains your AKS cluster.

Step 4: Verify the Cluster’s Power State

Check the status of the cluster to confirm it has been stopped:

az aks show --name YOUR_CLUSTER_NAME --resource-group YOUR_RESOURCE_GROUP --query "powerState"

If the cluster is successfully stopped, the output will display:

{
"code": "Stopped"
}

Step 5: Start the AKS Cluster

To start the cluster again, use the following command:

az aks start --name YOUR_CLUSTER_NAME --resource-group YOUR_RESOURCE_GROUP

Step 6: Verify the Cluster is Running

Check the cluster’s status to ensure it is running:

az aks show --name YOUR_CLUSTER_NAME --resource-group YOUR_RESOURCE_GROUP --query "powerState"

If the cluster is running, the output will display:

{
"code": "Running"
}

Key Features of Starting and Stopping AKS Clusters

  1. Cost Savings:
    Stop clusters when not in use to reduce compute costs.
  2. Preserved Configuration:
    Retains the cluster’s configuration, state, and data even when stopped.
  3. Ease of Use:
    Simple commands via Azure CLI make starting and stopping clusters quick and efficient.
  4. Automation Support:
    Can be integrated into automation scripts to manage clusters based on usage patterns.

Advantages of Starting and Stopping AKS Clusters

  1. Cost Efficiency:
    Pay only for the resources you use by stopping clusters during downtime.
  2. Flexibility:
    Easily start clusters during peak hours and stop them when they are not needed.
  3. Environment Preservation:
    Maintain all cluster settings and configurations while stopping the underlying resources.
  4. Automation Capabilities:
    Use Azure CLI or automation tools like Azure DevOps or PowerShell to schedule start/stop commands.

Disadvantages of Starting and Stopping AKS Clusters

  1. Downtime During Transition:
    The cluster will not be accessible while starting or stopping.
  2. Limited Preview Feature:
    As of now, this feature may require enabling preview functionality, which could involve additional steps.
  3. Time to Restart:
    Starting a stopped cluster can take several minutes, which may impact quick response needs.

Best Practices

  1. Schedule Cluster Management:
    Use automation scripts or Azure Logic Apps to schedule start/stop actions based on business hours.
  2. Monitor Resource Usage:
    Regularly monitor the utilization of your AKS cluster to identify when it can be stopped.
  3. Test the Workflow:
    Ensure all workloads and applications work seamlessly after starting the cluster.
  4. Set Alerts:
    Configure Azure Monitor alerts to notify you about the cluster’s status and ensure there are no unexpected downtimes.

Troubleshooting Steps

1. AKS Start/Stop Commands Not Working

  • Ensure the AKS Preview Extension is installed and updated.
  • Verify that the StartStopPreview feature is registered:
    bash
    az feature list -o table --query "[?contains(name,'Microsoft.ContainerService/StartStopPreview')].{Name:name, State:properties.state}"

2. Cluster Status Not Updating

  • Refresh the Azure Container Resource Provider:
    bash
    az provider register --namespace Microsoft.ContainerService

3. Long Start-Up Times

  • Check cluster node configurations for potential delays.
  • Verify network configurations to ensure no bottlenecks.

4. Automation Errors

  • Verify that Azure CLI commands are correctly integrated into your automation scripts.
  • Use Azure Monitor logs to debug automation failures.

Conclusion

Starting and stopping Azure Kubernetes Service (AKS) clusters is a powerful feature that enables organizations to save costs without losing the cluster’s configuration and data. Whether you’re running a production workload or a development environment, this capability can optimize resource usage effectively.

By following the steps outlined in this article, you can easily manage the lifecycle of your AKS clusters. For further automation, integrate these commands into CI/CD pipelines or schedule them using tools like Azure Automation or PowerShell scripts.

For more details, visit the official Azure Kubernetes Service documentation.

Related articles

How To Skip Git Commit Hooks

How to Skip Git Commit Hooks Git commit hooks are essential for maintaining code quality and enforcing best practices...

How to Install phpMyAdmin on Ubuntu

  Installing phpMyAdmin on Ubuntu phpMyAdmin is an open-source tool that simplifies managing MySQL or MariaDB databases via a web...

Software as a Service (SaaS)

Software as a Service (SaaS) Software as a Service (SaaS) is a cloud computing model that delivers software applications...

Automating Kubernetes Operations | Simplify and Scale Your Workflows

Automating Kubernetes Operations: Simplify and Scale Your Workflows Kubernetes, as a leading container orchestration platform, is powerful but can...