Creating AKS Cluster With ARM Template Using PowerShell

Introduction

 
The aim of this tutorial is to create and deploy an AKS Cluster with Resource Manager Template in PowerShell. These templates are for JSON files that define the resources that you are going to deploy. You can either create them from scratch (that won’t be covered here) or download them from Azure. Using ARM templates is mostly used for automation.
 
Prerequisites
 
You require an Azure subscription to perform these steps. If you don't have one, you can create one by following the steps outlined on the "Create your Azure free account today" webpage.
 

Road Map

  • Generate a template using the portal
  • Use the template to deploy the AKS Cluster

Generate a template using the portal

 
Open your browser and log into portal.azure.com.
  • Click on "create a resource".
  • Click on “Kubernetes Services” to start creating an AKS Cluster.

    Creating AKS Cluster With ARM Template Using PowerShell
Fill out the Basic tab.
 
Create a Resource Group if not available.
 
Type a unique Kubernetes cluster name.
 
Select a region, preferably East US.
 
Select Kubernetes version “1.14.6” which is an error generated at the validation process.
 
Creating AKS Cluster With ARM Template Using PowerShell 
 
Go to the Authentication tab.
 
Click on "Configure service principal" if the error is generated during validation.
 
Click on "Use existing service principal" and type the credentials for an existing service principal.
 
Creating AKS Cluster With ARM Template Using PowerShell 
 
Go to Monitoring tab and disable the container monitoring.
 
Now, click on Review + Create.
 
Creating AKS Cluster With ARM Template Using PowerShell 
 
After the validation has passed, don’t click "Create"; rather you want a template for automation. So, click on “Download a template for automation”.
 
Creating AKS Cluster With ARM Template Using PowerShell 
 
The following screen shows your template. Click on “Download” to download the template file.
 
Creating AKS Cluster With ARM Template Using PowerShell 
 
Once the template file is downloaded, you can now open your PowerShell. However, you would be needing the Azure PowerShell. Download and install it from here. To start working with Azure PowerShell, sign in with your Azure credentials, with the following commands in Azure.
 
>> Connect-AzAccount
 
Now, go to your downloaded templates. You will find a ‘JSON’ file there named template. This is the ‘template file’ that you will be using in your PowerShell.
 
Now open PowerShell and run the following command.
 
>> New-AzResourceGroupDeployment -ResourceGroupName <resource-group-name> -TemplateFile <path-to-template>
 
Where <resource-group-name> is the name of the resource group where you want to deploy the Cluster and <path-to-template> is the complete path to the template.json file. In my case it is “C:\Users\***********\Downloads\template2.0\template.json”
 
After you run the command, PowerShell will want user input as mentioned below. I have filled out the input for reference.
 
Creating AKS Cluster With ARM Template Using PowerShell 
 
You might get an error as follows,
 
Creating AKS Cluster With ARM Template Using PowerShell 
 
This will require you to either change your location or change the Kubernetes Version. I prefer changing the Kubernetes version. Run the following command to see the list of supported versions,
 
>> az aks get-versions --location eastus --output table
 
Once you get the list, copy any of the version numbers and open your template.json file in an editor. Search for Kubernetes Version and change the default value to your copied supported version. Save your file and open PowerShell.
 
If you didn’t get the error skip this step. Now Run the following command again,
 
>> New-AzResourceGroupDeployment -ResourceGroupName <resource-group-name> -TemplateFile <path-to-template>
 
Fill out the User Inputs and your AKS cluster should be created if no other errors and made.
 
I will be checking this blog regularly for any inquires. Feel free to comment below in case of any queries.
 

Summary

 
  1. Create a template for automation using the Azure Portal.
  2. Save the template on your local machine.
  3. Install Azure PowerShell and connect to your Account.
  4. Run the following PowerShell command,
  5. New-AzResourceGroupDeployment -ResourceGroupName <resource-group-name> -TemplateFile <path-to-template>
  6. Enter the User Inputs Required.
  7. Wait for the deployment to complete.


Similar Articles