Post

Schedule AKS clusters to run during Business Hours

Introduction

In the dynamic landscape of cloud computing, optimizing costs is a crucial aspect of managing resources effeciently.
Microsoft Azure Kubernetes Services (AKS) is a powerful platform for deploying, managing, and scaling containerized applications.
While AKS provides flexibility and scalability, it’s equally important for organizations to adopt cost-saving measures.
One effective strategy is shutting down and starting AKS clusters during business hours.

In this blog post, I will explore the benefits of shutting down AKS clusters in Azure to save costs on an authomatic approach.
I will use a low code Logic App approach to shutdown and startup the AKS clusters flagged by a specific tag.

This article can save you costs when running a couple of AKS clusters.

Starting with the start of a cluster

  1. Creating a Logic App like I did in my Azure environment (comsumption based)
    img-description

  2. Adding the tag to the AKS Cluster

    img-description

  3. Starting with the creationg of the flow in the Logic App.

Starting with Flow to start the AKS cluster

Adding some reccurence action to the logic app to make sure it will start before business hours.

  1. Start with a schedule action and list all the resources from a subscription

step 1 for Logic App Flow

  1. Extract the correct tags from the payload
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    
      {
     "items": {
         "properties": {
             "id": {
                 "type": "string"
             },
             "identity": {
                 "properties": {
                     "principalId": {
                         "type": "string"
                     },
                     "tenantId": {
                         "type": "string"
                     },
                     "type": {
                         "type": "string"
                     }
                 },
                 "type": "object"
             },
             "location": {
                 "type": "string"
             },
             "name": {
                 "type": "string"
             },
             "tags": {
                 "properties": {
                     "Hours": {
                         "type": "string"
                     }
                 },
                 "type": "object"
             },
             "type": {
                 "type": "string"
             }
         },
         "required": [
             "id",
             "name",
             "type",
             "location",
             "identity",
             "tags"
         ],
         "type": "object"
     },
     "type": "array"
    }
    

step 1 for Logic App Flow

  1. Now, we got all the resources that are tagged with Business, so they need to run only during business hours.
    Let’s start these AKS clusters with a Foreach.

Last step from the flow

Here you can find the code for the split function!

1
split(outputs('Get_resource_Id'),'/')[4]

Shutdown a AKS cluster after Business Hours

For the shutdown it’s the same flow only the last part is different.

Shutdown a cluster

Conlusion

In the shift to the cloud cost optimization remains a top priority for organizations leveraging services like Azure Kubernetes Service.
Shutting down AKS clusters during idle periods is a practical and effective strategy to reducing costs, aligning expenses with actual usage, and maintaining a secure and efficient cloud environment.

Happy Cloud! :)

P.S If you want receive the ARM template form the flows, just send me an e-mail ;)

This post is licensed under CC BY 4.0 by the author.

Trending Tags