Create an AKS Cluster Using Bicep

In this post, we are creating a Microsoft Azure Kubernetes Service (AKS) using the Infrastructure as code Bicep language.

The following template creates a Linux-based cluster with a single host in the agent pool. The cluster runs Kubernetes version 1.24.3.

The template also sets the admin user name using a parameter. The agent VM size is set to Standard_DS2_v2.

Because we are using a Linux agent, you must paste your Public SSH key in the Public Key section.

Template

The following template is good to start with AKS because it uses a single host. If you need to add hosts, increase the number next to the count option.

param location string = resourceGroup().location
param adminUsername string

resource aksCluster 'Microsoft.ContainerService/managedClusters@2021-03-01' = {
  name: 'ntweeklyaks'
  location: location
  identity: {
    type: 'SystemAssigned'
  }
  properties: {
    kubernetesVersion: '1.24.3'
    dnsPrefix: 'dnsprefix'
    enableRBAC: true
    agentPoolProfiles: [
      {
        name: 'agentpool'
        count: 1
        vmSize: 'Standard_DS2_v2'
        osType: 'Linux'
        mode: 'System'
      }
    ]
    linuxProfile: {
      adminUsername: adminUsername
      ssh: {
        publicKeys: [
          {
            keyData: 'SSH PUBLIC KEY GOES HERE'

          }
        ]
      }
    }
  }
}

Deploy Template

To deploy the template, run the following Azure CLI command.

 az deployment group create  --template-file AKS.bicep --resource-group biceplab2 --parameters adminUsername=vmadmin   --verbose

Processing…
Success! You're on the list.

Posted

in

,

by

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.