Scaling multiple kubernetes node pools on azure

10/7/2019

I am in the middle of creating a function to schedule node pool scaling on azure.

This was fairly easy using the AKS Module and creating a function to scale the nodepool, but now the development team has started using multuple node pools in the same kubernetes service, usually i would just use the Set-AzAks as follow

Set-AzAks -Name <name> -ResourceGroupName <rgname> -NodeCount 1

But i seem unable to specify individual node pools in the command. I have been able to use the az CLI tool to get the functionality i want doing it manually, but I really want to use the azure automation account to do this.

Any help would be appreciated

-- Shadesfear
azure
azure-kubernetes
kubernetes
powershell

1 Answer

10/9/2019

This is an issue which already existed in the Github. So I think it's not a good way to use the PowerShell command Set-AzAks to scale the AKS nodes count in the current situation.

For this, I recommend you to use the Azure REST API Managed Clusters - Create Or Update through PowerShell, it will also work perfectly as the Azure CLI commands for you.

Update:

As you wish, I will show you the example below:

$body = '{
  "location": "eastus",
  "properties": {
    "kubernetesVersion": "1.14.6",
    "dnsPrefix": "xxxxx",
    "agentPoolProfiles": [
      {
        "count": 2,
        "vmSize": "Standard_DS2_v2",
        "osDiskSizeGB": 100,
        "vnetSubnetID": "xxxxxxxx",
        "maxPods": 30,
        "osType": "Linux",
        "type": "AvailabilitySet",
        "orchestratorVersion": "1.14.6",
        "name": "agentpool"
      }
    ],
    "addonProfiles": {
      "httpapplicationrouting": {
        "enabled": false,
        "config": {}
      },
      "omsagent": {
        "enabled": true,
        "config": {
          "loganalyticsworkspaceresourceid": "xxxxxxxx"
        }
      }
    },
    "nodeResourceGroup": "xxxxxxxxx",
    "enableRBAC": true,
    "networkProfile": {
      "networkPlugin": "azure",
      "serviceCidr": "10.1.0.0/16",
      "dnsServiceIP": "10.1.0.10",
      "dockerBridgeCidr": "172.17.0.1/16",
      "loadBalancerSku": "Basic"
    }
  }
}'
$requestUri = "https://management.azure.com/subscriptions/{subscription_id}/resourceGroups/{your_group_name}/providers/Microsoft.ContainerService/managedClusters/{your_cluster_name}?api-version=2019-08-01"
$accessToken = "xxxxxxx"
Invoke-RestMethod -Headers @{Authorization = "Bearer $accessToken"} -Uri $requestUri -Method PUT -ContentType 'application/json' -Body $body

You can change the context in the body as you need and the properties describe in the REST API.

-- Charles Xu
Source: StackOverflow