Automating start/stop AKS cluster using Azure Automation account
Azure Kubernetes Service (AKS) is a fully managed Kubernetes service that makes it easy to deploy and manage containerized applications. However, running an AKS cluster 24/7 can be expensive. In this blog post, we’ll walk through how to automate starting and stopping an AKS cluster using Azure Automation account.
Introduction
Azure Automation account is a cloud-based automation and configuration management service that provides a way to automate the creation, deployment, monitoring, and maintenance of resources in your Azure environment. In this blog post, we’ll use Azure Automation account to automate starting and stopping an AKS cluster.
Step 1: Create an Azure Automation Account
The first step is to create an Azure Automation account. If you don’t already have an Azure account, you can sign up for a free account at https://azure.microsoft.com/en-us/free/. Once you’ve signed up, create a new Automation account and give it a name.
Step 2: Create a Start and Stop Runbook
Next, create two runbooks in your Automation account: one for starting the AKS cluster and one for stopping the AKS cluster. To create a runbook, navigate to your Automation account and click on “Runbooks” in the left-hand menu. Click on “Create a runbook” and give it a name.
For the aks-start-stop runbook, add the following PowerShell code:
Please adjust the time as required to your current time.
These runbooks use the Azure PowerShell module to start and stop the AKS cluster. Make sure to replace myResourceGroup and myAKSCluster with the appropriate values for your AKS cluster.
Step 3: Create a Schedule
Now that you have your runbooks, you can create a schedule to run them. To create a schedule, navigate to your Automation account and click on “Schedules” in the left-hand menu. Click on “Add a schedule” and give it a name.
For the start schedule, set the “Start time” to the time you want your AKS cluster to start. For the stop schedule, set the “Start time” to the time you want your AKS cluster to stop.
Step 4: Link the Runbooks to the Schedule
Finally, link the runbooks to the schedule. To do this, navigate to your schedule and click on “Link a runbook” in the “Runbook” section. Select the appropriate runbook and click “OK”. Repeat this step for the other runbook.
Conclusion
In this blog post, we walked through how to automate starting and stopping an AKS cluster using Azure Automation account. By automating this process, you can save money on your Azure bill and ensure that your AKS cluster is only running when it’s needed. With Azure Automation account, you can easily manage your AKS cluster and streamline your infrastructure management.