Azure Container Node Pool
This page shows how to write Terraform and Azure Resource Manager for Container Node Pool and write them securely.
azurerm_kubernetes_cluster_node_pool (Terraform)
The Node Pool in Container can be configured in Terraform with the resource name azurerm_kubernetes_cluster_node_pool
. The following sections describe 10 examples of how to use the resource and its parameters.
Example Usage from GitHub
resource "azurerm_kubernetes_cluster_node_pool" "example" {
name = "internal"
kubernetes_cluster_id = azurerm_kubernetes_cluster.example.id
vm_size = "Standard_DS2_v2"
}
resource "azurerm_kubernetes_cluster_node_pool" "taas-sv-pool" {
name = var.svpool_name
kubernetes_cluster_id = var.kubernetes_cluster_id
#kubernetes_cluster_id = azurerm_kubernetes_cluster
#kubernetes_cluster_id = module.aks-cluster.azurerm_kubernetes_cluster_id
enable_auto_scaling = var.svpool_enable_auto_scaling
resource "azurerm_kubernetes_cluster_node_pool" "user" {
count = var.usernodepool_enabled ? 1 : 0
availability_zones = [1, 2, 3]
enable_auto_scaling = true
kubernetes_cluster_id = azurerm_kubernetes_cluster.aks.id
resource "azurerm_kubernetes_cluster_node_pool" "autoscale_node_pool" {
count = var.enable_auto_scaling ? 1 : 0
name = var.node_pool_name
kubernetes_cluster_id = var.aks_cluster_id
vnet_subnet_id = var.vnet_subnet_id
availability_zones = var.availability_zones
resource "azurerm_kubernetes_cluster_node_pool" "example" {
name = "internal"
kubernetes_cluster_id = azurerm_kubernetes_cluster.example.id
vm_size = "Standard_DS2_v2"
}
resource "azurerm_kubernetes_cluster_node_pool" "apppool01_spot" {
count = var.k8s_properties.apppool01_is_spot ? 1 : 0
name = var.k8s_properties.apppool01_name
kubernetes_cluster_id = azurerm_kubernetes_cluster.aks-np.id
vm_size = var.k8s_properties.apppool01_size
#node_count = 1
resource "azurerm_kubernetes_cluster_node_pool" "autoscale_node_pool" {
count = var.enable_auto_scaling ? 1 : 0
name = var.node_pool_name
kubernetes_cluster_id = var.aks_cluster_id
vnet_subnet_id = var.vnet_subnet_id
availability_zones = var.availability_zones
resource "azurerm_kubernetes_cluster_node_pool" "main" {
for_each = var.node_pools
name = each.value.name
kubernetes_cluster_id = azurerm_kubernetes_cluster.main.id
vm_size = each.value.vm_size
node_count = each.value.node_count
resource "azurerm_kubernetes_cluster_node_pool" "spot" {
for_each = local.spot_node_pools
lifecycle {
ignore_changes = [
node_count,
resource "azurerm_kubernetes_cluster_node_pool" "windows" {
name = "win"
enable_node_public_ip = false
os_type = "Windows"
os_disk_size_gb = 100
os_disk_type = "Managed"
Parameters
-
availability_zones
optional - list of string -
enable_auto_scaling
optional - bool -
enable_host_encryption
optional - bool -
enable_node_public_ip
optional - bool -
eviction_policy
optional - string -
id
optional computed - string -
kubernetes_cluster_id
required - string -
max_count
optional - number -
max_pods
optional computed - number -
min_count
optional - number -
mode
optional - string -
name
required - string -
node_count
optional computed - number -
node_labels
optional - map from string to string -
node_taints
optional - list of string -
orchestrator_version
optional computed - string -
os_disk_size_gb
optional computed - number -
os_disk_type
optional - string -
os_type
optional - string -
priority
optional - string -
proximity_placement_group_id
optional - string -
spot_max_price
optional - number -
tags
optional - map from string to string -
vm_size
required - string -
vnet_subnet_id
optional - string -
timeouts
single block -
upgrade_settings
list block-
max_surge
required - string
-
Explanation in Terraform Registry
Manages a Node Pool within a Kubernetes Cluster -> Note: Due to the fast-moving nature of AKS, we recommend using the latest version of the Azure Provider when using AKS - you can find the latest version of the Azure Provider here.
NOTE: Multiple Node Pools are only supported when the Kubernetes Cluster is using Virtual Machine Scale Sets.
Tips: Best Practices for The Other Azure Container Resources
In addition to the azurerm_kubernetes_cluster, Azure Container has the other resources that should be configured for security reasons. Please check some examples of those resources and precautions.
azurerm_kubernetes_cluster
Ensure to enable logging for AKS
It is better to enable AKS logging to Azure Monitoring. This provides useful information regarding access and usage.
Microsoft.ContainerService/managedClusters/agentPools (Azure Resource Manager)
The managedClusters/agentPools in Microsoft.ContainerService can be configured in Azure Resource Manager with the resource name Microsoft.ContainerService/managedClusters/agentPools
. The following sections describe how to use the resource and its parameters.
Example Usage from GitHub
An example could not be found in GitHub.
Parameters
apiVersion
required - stringname
required - stringThe name of the agent pool.
properties
requiredavailabilityZones
optional - arrayThe list of Availability zones to use for nodes. This can only be specified if the AgentPoolType property is 'VirtualMachineScaleSets'.
count
optional - integerNumber of agents (VMs) to host docker containers. Allowed values must be in the range of 0 to 1000 (inclusive) for user pools and in the range of 1 to 1000 (inclusive) for system pools. The default value is 1.
creationData
optionalsourceResourceId
optional - stringThis is the ARM ID of the source object to be used to create the target object.
enableAutoScaling
optional - booleanWhether to enable auto-scaler
enableEncryptionAtHost
optional - booleanThis is only supported on certain VM sizes and in certain Azure regions. For more information, see: https://docs.microsoft.com/azure/aks/enable-host-encryption
enableFIPS
optional - booleanSee Add a FIPS-enabled node pool for more details.
enableNodePublicIP
optional - booleanSome scenarios may require nodes in a node pool to receive their own dedicated public IP addresses. A common scenario is for gaming workloads, where a console needs to make a direct connection to a cloud virtual machine to minimize hops. For more information see assigning a public IP per node. The default is false.
enableUltraSSD
optional - booleanWhether to enable UltraSSD
gpuInstanceProfile
optional - stringGPUInstanceProfile to be used to specify GPU MIG instance profile for supported GPU VM SKU.
kubeletConfig
optionalallowedUnsafeSysctls
optional - arrayAllowed list of unsafe sysctls or unsafe sysctl patterns (ending in
*
).containerLogMaxFiles
optional - integerThe maximum number of container log files that can be present for a container. The number must be ≥ 2.
containerLogMaxSizeMB
optional - integerThe maximum size (e.g. 10Mi) of container log file before it is rotated.
cpuCfsQuota
optional - booleanThe default is true.
cpuCfsQuotaPeriod
optional - stringThe default is '100ms.' Valid values are a sequence of decimal numbers with an optional fraction and a unit suffix. For example: '300ms', '2h45m'. Supported units are 'ns', 'us', 'ms', 's', 'm', and 'h'.
cpuManagerPolicy
optional - stringThe default is 'none'. See Kubernetes CPU management policies for more information. Allowed values are 'none' and 'static'.
failSwapOn
optional - booleanIf set to true it will make the Kubelet fail to start if swap is enabled on the node.
imageGcHighThreshold
optional - integerTo disable image garbage collection, set to 100. The default is 85%
imageGcLowThreshold
optional - integerThis cannot be set higher than imageGcHighThreshold. The default is 80%
podMaxPids
optional - integerThe maximum number of processes per pod.
topologyManagerPolicy
optional - stringFor more information see Kubernetes Topology Manager. The default is 'none'. Allowed values are 'none', 'best-effort', 'restricted', and 'single-numa-node'.
kubeletDiskType
optional - stringlinuxOSConfig
optionalswapFileSizeMB
optional - integerThe size in MB of a swap file that will be created on each node.
sysctls
optionalfsAioMaxNr
optional - integerSysctl setting fs.aio-max-nr.
fsFileMax
optional - integerSysctl setting fs.file-max.
fsInotifyMaxUserWatches
optional - integerSysctl setting fs.inotify.max_user_watches.
fsNrOpen
optional - integerSysctl setting fs.nr_open.
kernelThreadsMax
optional - integerSysctl setting kernel.threads-max.
netCoreNetdevMaxBacklog
optional - integerSysctl setting net.core.netdev_max_backlog.
netCoreOptmemMax
optional - integerSysctl setting net.core.optmem_max.
netCoreRmemDefault
optional - integerSysctl setting net.core.rmem_default.
netCoreRmemMax
optional - integerSysctl setting net.core.rmem_max.
netCoreSomaxconn
optional - integerSysctl setting net.core.somaxconn.
netCoreWmemDefault
optional - integerSysctl setting net.core.wmem_default.
netCoreWmemMax
optional - integerSysctl setting net.core.wmem_max.
netIpv4IpLocalPortRange
optional - stringSysctl setting net.ipv4.ip_local_port_range.
netIpv4NeighDefaultGcThresh1
optional - integerSysctl setting net.ipv4.neigh.default.gc_thresh1.
netIpv4NeighDefaultGcThresh2
optional - integerSysctl setting net.ipv4.neigh.default.gc_thresh2.
netIpv4NeighDefaultGcThresh3
optional - integerSysctl setting net.ipv4.neigh.default.gc_thresh3.
netIpv4TcpFinTimeout
optional - integerSysctl setting net.ipv4.tcp_fin_timeout.
netIpv4TcpkeepaliveIntvl
optional - integerSysctl setting net.ipv4.tcp_keepalive_intvl.
netIpv4TcpKeepaliveProbes
optional - integerSysctl setting net.ipv4.tcp_keepalive_probes.
netIpv4TcpKeepaliveTime
optional - integerSysctl setting net.ipv4.tcp_keepalive_time.
netIpv4TcpMaxSynBacklog
optional - integerSysctl setting net.ipv4.tcp_max_syn_backlog.
netIpv4TcpMaxTwBuckets
optional - integerSysctl setting net.ipv4.tcp_max_tw_buckets.
netIpv4TcpTwReuse
optional - booleanSysctl setting net.ipv4.tcp_tw_reuse.
netNetfilterNfConntrackBuckets
optional - integerSysctl setting net.netfilter.nf_conntrack_buckets.
netNetfilterNfConntrackMax
optional - integerSysctl setting net.netfilter.nf_conntrack_max.
vmMaxMapCount
optional - integerSysctl setting vm.max_map_count.
vmSwappiness
optional - integerSysctl setting vm.swappiness.
vmVfsCachePressure
optional - integerSysctl setting vm.vfs_cache_pressure.
transparentHugePageDefrag
optional - stringValid values are 'always', 'defer', 'defer+madvise', 'madvise' and 'never'. The default is 'madvise'. For more information see Transparent Hugepages.
transparentHugePageEnabled
optional - stringValid values are 'always', 'madvise', and 'never'. The default is 'always'. For more information see Transparent Hugepages.
maxCount
optional - integerThe maximum number of nodes for auto-scaling
maxPods
optional - integerThe maximum number of pods that can run on a node.
minCount
optional - integerThe minimum number of nodes for auto-scaling
mode
optional - stringnodeLabels
optional - stringThe node labels to be persisted across all nodes in agent pool.
nodePublicIPPrefixID
optional - stringThis is of the form: /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/publicIPPrefixes/{publicIPPrefixName}
nodeTaints
optional - arrayThe taints added to new nodes during node pool create and scale. For example, key=value:NoSchedule.
orchestratorVersion
optional - stringAs a best practice, you should upgrade all node pools in an AKS cluster to the same Kubernetes version. The node pool version must have the same major version as the control plane. The node pool minor version must be within two minor versions of the control plane version. The node pool version cannot be greater than the control plane version. For more information see upgrading a node pool.
osDiskSizeGB
optional - integerOS Disk Size in GB to be used to specify the disk size for every machine in the master/agent pool. If you specify 0, it will apply the default osDisk size according to the vmSize specified.
osDiskType
optional - stringosSKU
optional - stringosType
optional - stringpodSubnetID
optional - stringIf omitted, pod IPs are statically assigned on the node subnet (see vnetSubnetID for more details). This is of the form: /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworks/{virtualNetworkName}/subnets/{subnetName}
powerState
optionalcode
optional - stringTells whether the cluster is Running or Stopped.
proximityPlacementGroupID
optional - stringThe ID for Proximity Placement Group.
scaleDownMode
optional - stringThis also effects the cluster autoscaler behavior. If not specified, it defaults to Delete.
scaleSetEvictionPolicy
optional - stringThis cannot be specified unless the scaleSetPriority is 'Spot'. If not specified, the default is 'Delete'.
scaleSetPriority
optional - stringThe Virtual Machine Scale Set priority. If not specified, the default is 'Regular'.
spotMaxPrice
optional - numberPossible values are any decimal value greater than zero or -1 which indicates the willingness to pay any on-demand price. For more details on spot pricing, see spot VMs pricing
tags
optional - stringThe tags to be persisted on the agent pool virtual machine scale set.
type
optional - stringupgradeSettings
optionalmaxSurge
optional - stringThis can either be set to an integer (e.g. '5') or a percentage (e.g. '50%'). If a percentage is specified, it is the percentage of the total agent pool size at the time of the upgrade. For percentages, fractional nodes are rounded up. If not specified, the default is 1. For more information, including best practices, see: https://docs.microsoft.com/azure/aks/upgrade-cluster#customize-node-surge-upgrade
vmSize
optional - stringVM size availability varies by region. If a node contains insufficient compute resources (memory, cpu, etc) pods might fail to run correctly. For more details on restricted VM sizes, see: https://docs.microsoft.com/azure/aks/quotas-skus-regions
vnetSubnetID
optional - stringIf this is not specified, a VNET and subnet will be generated and used. If no podSubnetID is specified, this applies to nodes and pods, otherwise it applies to just nodes. This is of the form: /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworks/{virtualNetworkName}/subnets/{subnetName}
workloadRuntime
optional - string
type
required - string
Frequently asked questions
What is Azure Container Node Pool?
Azure Container Node Pool is a resource for Container of Microsoft Azure. Settings can be wrote in Terraform.
Where can I find the example code for the Azure Container Node Pool?
For Terraform, the gilyas/infracost, praveens-arch/sv-readyapi-cloud-infra and johnarok/azure-aks-sample source code examples are useful. See the Terraform Example section for further details.