Automating start/stop AKS cluster using Azure Automation account
Date published:
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.
Install Azaks module in Azure Automation account. You can do this by navigating to your Automation account and clicking on “Modules” in the left-hand menu. Click on “Browse gallery” and search for “Azaks”. Click on the module and then click “Import”.
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 per your current time zone.
These runbooks use the Azure PowerShell module to start and stop the AKS cluster. Make sure to replace aksName and resourceGroup 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.
Please remember that you need to add credentials to the runbook. You can do this by navigating to your runbook and select on “Credentials” and then “Add a credential”.
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.