Mange node for kubernetes cluster

Samuel.Yan 61 Reputation points
2021-09-16T07:33:43.31+00:00

I has created a k8s cluster with AvailabilitySet.The create command is like the following.

az aks create --name demo -g demo1--vm-set-type AvailabilitySet --network-plugin azure --load-balancer-sku 
Standard

How do I add/delete nodes using azure-cli and python sdk.,Use AvailabilitySet api or nodepool api?
Should I create vm&nic&disk in advance?

Thanks!

Azure Kubernetes Service (AKS)
Azure Kubernetes Service (AKS)
An Azure service that provides serverless Kubernetes, an integrated continuous integration and continuous delivery experience, and enterprise-grade security and governance.
1,855 questions
{count} votes

Accepted answer
  1. SRIJIT-BOSE-MSFT 4,326 Reputation points Microsoft Employee
    2021-09-16T16:45:10.557+00:00

    @Samuel.Yan , Thank you for your question. Since you have created an AKS cluster with --vm-set-type set to AvailabilitySet, you can scale your cluster up/down to add/remove nodes respectively.

    In Azure CLI this can be implemented as:

    az aks scale --resource-group $ClusterResourceGroup --name $ClusterName   --node-count $DesiredNodeCount  
    

    For more information please check here.

    Using Azure Python SDK you can define the scale function:

    def aks_scale(cmd, client, resource_group_name, name, node_count, nodepool_name="", no_wait=False):  
        instance = client.get(resource_group_name, name)  
      
        if len(instance.agent_pool_profiles) > 1 and nodepool_name == "":  
            raise CLIError('There are more than one node pool in the cluster. '  
                           'Please specify nodepool name or use az aks nodepool command to scale node pool')  
      
        if node_count == 0:  
            raise CLIError("Can't scale down to 0 nodes.")  
        for agent_profile in instance.agent_pool_profiles:  
            if agent_profile.name == nodepool_name or (nodepool_name == "" and len(instance.agent_pool_profiles) == 1):  
                agent_profile.count = int(node_count)  # pylint: disable=no-member  
                # null out the SP and AAD profile because otherwise validation complains  
                instance.service_principal_profile = None  
                instance.aad_profile = None  
                return sdk_no_wait(no_wait, client.create_or_update, resource_group_name, name, instance)  
        raise CLIError('The nodepool "{}" was not found.'.format(nodepool_name))  
    

    as described here.

    For more information please check the Container Service Management Library azure-mgmt-containerservice.

    You need not manage the infrastructural resources (like VM, NIC, OS Disk etc) manually and we highly recommend against doing so as these might have adverse effects of desynchronization with the AKS control plane. Microsoft.ContainerService Resource Provider will manage these for you under the hood if you are using az aks commands or the azure-mgmt-containerservice Azure Python SDK Library to operate on your AKS cluster.

    ----
    Hope this helps.

    Please "Accept as Answer" if it helped, so that it can help others in the community looking for help on similar topics.


1 additional answer

Sort by: Most helpful
  1. SUNOJ KUMAR YELURU 13,936 Reputation points MVP
    2021-09-16T16:03:13.923+00:00

    Hi @Samuel.Yan

    To add and delete nodes using azure-cli
    https://learn.microsoft.com/en-us/azure/aks/virtual-nodes-cli

    Creates or updates an agent pool in the specified managed cluster.
    https://learn.microsoft.com/en-us/rest/api/aks/agent-pools/create-or-update

    If the Answer is helpful, please click Accept Answer and up-vote, so that it can help others in the community looking for help on similar topics.

    0 comments No comments