Search⌘ K
AI Features

Creating Worker Nodes

Understand how to define and manage worker node pools in AKS clusters using Terraform. This lesson guides you through creating additional node pools, adjusting VM sizes, enabling auto-scaling, and removing resources, ensuring you can maintain desired cluster states effectively.

Defining worker nodes

We can manage worker node pools (beyond the default one) through the azurerm_kubernetes_cluster_node_pool module. We’ve prepared yet another definition that we can use.

Shell
resource "azurerm_kubernetes_cluster_node_pool" "secondary" {
name = "${var.cluster_name}2"
kubernetes_cluster_id = azurerm_kubernetes_cluster.primary.id
vm_size = var.machine_type
enable_auto_scaling = true
max_count = var.max_node_count
min_count = var.min_node_count
}

Explaining the output

  • Line 2: We define the name of the node pool.
  • Line 3: We define the ID of the Kubernetes cluster (kubernetes_cluster_id). Instead of hard-coding it or setting to a value, we’re telling Terraform to use the ID field of the azurerm_kubernetes_cluster.primary resource.
  • Lines 4–7: Further on, we have the size of the VMs (vm_size), whether auto-scaling should be enabled (enable_auto_scaling), and the maximum (
...