aks nodepool neither increases nor decreases through terraform

10/18/2020

At the time of creation, it creates desired node count specified but when values of node count or min count for nodepool are changed then the changes are not reflected.

resource "azurerm_kubernetes_cluster" "aks" {
  name                = var.cluster-name
  location            = var.cluster-region
  resource_group_name = var.rg
  dns_prefix          = var.cluster-dns_prefix

  tags = {
    Environment = var.cluster-tag
  }

  default_node_pool {
    name                = var.prod-node-name
    type                = "VirtualMachineScaleSets"
    enable_auto_scaling = "true"
    //node_count          = var.prod-node-count
    max_count           = var.prod-max-count
    min_count           = var.prod-min-count
    vm_size             = var.prod-vm-size
    vnet_subnet_id      = azurerm_subnet.aks-stage-sub.id
    node_labels         = { "node_pool" = "prod" }
  }
  service_principal {
    client_id     = var.client_id
    client_secret = var.client_secret
  }
}

resource "azurerm_kubernetes_cluster_node_pool" "dev" {
  name                  = "dev"
  kubernetes_cluster_id = azurerm_kubernetes_cluster.aks.id
  vm_size               = var.dev-vm-size
  enable_auto_scaling   = "true"
  mode			= "User"
  node_count		= 2
  max_count             = 5
  min_count             = 1
  vnet_subnet_id        = azurerm_subnet.aks-stage-sub.id
  node_labels           = { "node_pool" = "dev" }

  tags = {
    Environment = var.dev-tag
  }
}

output "kube_config" {
  value = azurerm_kubernetes_cluster.aks.kube_config_raw
}

NOTE: At the first time of resource creating it created 2 nodes in dev nodepool but later increased the node count of dev nodepool to 3. Applied the terraform and did kubectl get nodes it showed only 2 nodes in dev nodepool. i tried many times but node count is not reflecting.

Thank you in advance.

-- Tenzin Lama
autoscaling
azure-aks
kubernetes
nodes
terraform

1 Answer

10/19/2020

In the documentation is says that node_count is the initial number of nodes which should exist within this Node Pool. I think that since enable_auto_scaling is set to true, the node_count will only affect the number of nodes at creation time and then the autoscaling configuration will be used to defined the correct number of nodes. If you want to be able to change the number of node after the creation of the node pool, maybe you should desactivate the autoscaling or change the autoscaling configuration

-- Jean-Philippe Bond
Source: StackOverflow