

Azure Resource Manager templates – Deploy an AKS cluster with multiple node pool...
source link: https://www.danielstechblog.io/azure-resource-manager-templates-deploy-an-aks-cluster-with-multiple-node-pools/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

This week the multiple node pool feature for Azure Kubernetes Service went GA.
Today we walk through the steps to deploy multiple AKS node pools with Azure Resource Manager templates.
Looking at the ARM template reference for AKS, node pools get defined in the managedClusters resource and additional node pools with an agentPools resource.
We could define multiple node pools statically, but we are using the copy object in the managedClusters resource to define them dynamically and deploying the AKS cluster with multiple node pools.
It is the same approach I already talked about using Terraform.
... "resources": [ { "apiVersion": "[variables('apiVersion').aks]", "type": "Microsoft.ContainerService/managedClusters", "name": "[parameters('name')]", "location": "[resourceGroup().location]", "properties": { ... "copy": [ { "name": "agentPoolProfiles", "count": "[length(parameters('agentPoolProfiles'))]", "input": { "name": "[concat('nodepool',add(copyIndex('agentPoolProfiles'),1))]", "maxPods": 250, "osDiskSizeGB": 128, "count": "[parameters('agentPoolProfiles')[copyIndex('agentPoolProfiles')].nodeCount]", "vmSize": "[parameters('agentPoolProfiles')[copyIndex('agentPoolProfiles')].nodeVmSize]", "osType": "Linux", "vnetSubnetID": "[variables('agentPoolProfiles').vnetSubnetId]", "enableAutoScaling": "[if(parameters('agentPoolProfiles')[copyIndex('agentPoolProfiles')].enableAutoScaling, parameters('agentPoolProfiles')[copyIndex('agentPoolProfiles')].enableAutoScaling, json('null'))]", "maxCount": "[if(parameters('agentPoolProfiles')[copyIndex('agentPoolProfiles')].enableAutoScaling, parameters('agentPoolProfiles')[copyIndex('agentPoolProfiles')].maxCount, json('null'))]", "minCount": "[if(parameters('agentPoolProfiles')[copyIndex('agentPoolProfiles')].enableAutoScaling, parameters('agentPoolProfiles')[copyIndex('agentPoolProfiles')].minCount, json('null'))]", "type": "VirtualMachineScaleSets", "availabilityZones": "[parameters('agentPoolProfiles')[copyIndex('agentPoolProfiles')].availabilityZones]" } } ], ... ], ...
The node pool configuration is specified with an array parameter.
... "agentPoolProfiles": { "value": [ { "nodeCount": 3, "nodeVmSize": "Standard_D2_v3", "availabilityZones": [ "1", "2", "3" ], "enableAutoScaling": true, "maxCount": 6, "minCount": 3 }, { "nodeCount": 2, "nodeVmSize": "Standard_D2_v3", "availabilityZones": null, "enableAutoScaling": false } ] }, ...
If we want to add additional node pools after our AKS cluster deployment happened, we cannot do that with the managedClusters resource leveraging the copy object. We would then receive the following error message.
Azure Error: InvalidTemplateDeployment Message: The template deployment 'aks' is not valid according to the validation procedure. The tracking id is '7302060e-9acf-430f-944b-5f0b4c9fb0d3'. See inner errors for details. Exception Details: Error Code: BadRequest Message: Provisioning of resource(s) for container service azst-aks-demo in resource group azst-aks-demo failed. Message: { "code": "BadRequest", "message": "A new agent pool was introduced. Adding agent pools to an existing cluster is not allowed through managed cluster operations. For agent pool specific change, please use per agent pool operations: https://aka.ms/agent-pool-rest-api", "target": "agentPoolProfiles" }. Details: ...
We need a second ARM template with the agentPools resource.
... "resources": [ { "apiVersion": "[variables('apiVersion').aks]", "type": "Microsoft.ContainerService/managedClusters/agentPools", "name": "[concat(parameters('name'),'/nodepool',add(copyIndex('agentPoolProfiles'),1))]", "location": "[resourceGroup().location]", "copy": { "name": "agentPoolProfiles", "count": "[length(parameters('agentPoolProfiles'))]" }, "properties": { "maxPods": 250, "osDiskSizeGB": 128, "count": "[parameters('agentPoolProfiles')[copyIndex('agentPoolProfiles')].nodeCount]", "vmSize": "[parameters('agentPoolProfiles')[copyIndex('agentPoolProfiles')].nodeVmSize]", "osType": "Linux", "vnetSubnetID": "[variables('agentPoolProfiles').vnetSubnetId]", "enableAutoScaling": "[if(parameters('agentPoolProfiles')[copyIndex('agentPoolProfiles')].enableAutoScaling, parameters('agentPoolProfiles')[copyIndex('agentPoolProfiles')].enableAutoScaling, json('null'))]", "maxCount": "[if(parameters('agentPoolProfiles')[copyIndex('agentPoolProfiles')].enableAutoScaling, parameters('agentPoolProfiles')[copyIndex('agentPoolProfiles')].maxCount, json('null'))]", "minCount": "[if(parameters('agentPoolProfiles')[copyIndex('agentPoolProfiles')].enableAutoScaling, parameters('agentPoolProfiles')[copyIndex('agentPoolProfiles')].minCount, json('null'))]", "type": "VirtualMachineScaleSets", "availabilityZones": "[parameters('agentPoolProfiles')[copyIndex('agentPoolProfiles')].availabilityZones]" } } ], ...
Even in this template we are using the copy object. That requires the specification of the configuration of the already existing node pools and the new ones.
... "agentPoolProfiles": { "value": [ { "nodeCount": 3, "nodeVmSize": "Standard_D2_v3", "availabilityZones": [ "1", "2", "3" ], "enableAutoScaling": true, "maxCount": 6, "minCount": 3 }, { "nodeCount": 2, "nodeVmSize": "Standard_D2_v3", "availabilityZones": null, "enableAutoScaling": false }, { "nodeCount": 1, "nodeVmSize": "Standard_D2_v3", "availabilityZones": [ "1", "2", "3" ], "enableAutoScaling": true, "maxCount": 3, "minCount": 1 } ] }, ...
Finally, we can deploy the AKS cluster with two node pools in Azure.
az group deployment create -g azst-aks-demo --template-file aks.json --parameters aks.parameters.json --verbose
As seen in the screenshot we got two node pools.
Now we add a third node pool with the second Azure Resource Manager template to the AKS cluster.
az group deployment create -g azst-aks-demo --template-file aks-nodepool.json --parameters aks-nodepool.parameters.json --verbose
You can find my ARM templates in my GitHub repository.
-> https://github.com/neumanndaniel/armtemplates/tree/master/container
Recommend
-
47
Popeye - A Kubernetes Cluster Sanitizer Popeye is a utility that cruises Kubernetes cluster resources and reports potential issues with your deployment manifests and configurations. By scanning your clusters, i...
-
39
Attention! I apologize for the automatic translation of this text. You can improve it by sending me a more correct version of the text or fix html pages via GITHUB repository...
-
14
How To Automatically Deploy ARM Templates To Azure Cosmos EmulatorThe Azure Cosmos Emulatorprovides a l...
-
16
Azure Resource Manager PowerShell Module Quirk If you’ve used the Azure Resource Manager (AzureRM) PowerShell module much, you may have noticed it may sometimes behave strangely. In this post, I’m going to share one that...
-
5
Unix time format in Azure Resource Manager templates The Unix time format is represented in seconds elapsed since 01.01.1970 UTC. So, it is different from the standard time format we are used to.Depending on the Azure service...
-
14
Azure Resource Manager (ARM) templates are a great way to deploy and manage resources in Azure. With the new Microsoft Learn learning path, you can learn who you can get started with Azure Resource Manager (ARM) templates. What is Azu...
-
11
Configuring Sahara cluster templates with the Python client 25 Sep 2014 Shout out to Erik Erlandson for introducing me to Baker. Recently I have been working on...
-
12
Deploy Microservices to multiple Environments using Azure DevOps 3 days ago2021-06-14T00:00:00+02:00 by Wolfgang Ofner 13 minA nice feature of Kubernetes is that you can easily set up new env...
-
10
Exploring ARM Templates: Azure Resource Manager TutorialInside Out Security Blog » Active Directory » Exploring ARM Templates: A...
-
8
Spark-shell on yarn resource manager: Basic steps to create hadoop cluster and run spark on it Reading Time: 3 minutesIn t...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK