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_zonesoptional - list of string -
enable_auto_scalingoptional - bool -
enable_host_encryptionoptional - bool -
enable_node_public_ipoptional - bool -
eviction_policyoptional - string -
idoptional computed - string -
kubernetes_cluster_idrequired - string -
max_countoptional - number -
max_podsoptional computed - number -
min_countoptional - number -
modeoptional - string -
namerequired - string -
node_countoptional computed - number -
node_labelsoptional - map from string to string -
node_taintsoptional - list of string -
orchestrator_versionoptional computed - string -
os_disk_size_gboptional computed - number -
os_disk_typeoptional - string -
os_typeoptional - string -
priorityoptional - string -
proximity_placement_group_idoptional - string -
spot_max_priceoptional - number -
tagsoptional - map from string to string -
vm_sizerequired - string -
vnet_subnet_idoptional - string -
timeoutssingle block -
upgrade_settingslist block-
max_surgerequired - 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
apiVersionrequired - stringnamerequired - stringThe name of the agent pool.
propertiesrequiredavailabilityZonesoptional - arrayThe list of Availability zones to use for nodes. This can only be specified if the AgentPoolType property is 'VirtualMachineScaleSets'.
countoptional - 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.
creationDataoptionalsourceResourceIdoptional - stringThis is the ARM ID of the source object to be used to create the target object.
enableAutoScalingoptional - booleanWhether to enable auto-scaler
enableEncryptionAtHostoptional - 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
enableFIPSoptional - booleanSee Add a FIPS-enabled node pool for more details.
enableNodePublicIPoptional - 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.
enableUltraSSDoptional - booleanWhether to enable UltraSSD
gpuInstanceProfileoptional - stringGPUInstanceProfile to be used to specify GPU MIG instance profile for supported GPU VM SKU.
kubeletConfigoptionalallowedUnsafeSysctlsoptional - arrayAllowed list of unsafe sysctls or unsafe sysctl patterns (ending in
*).containerLogMaxFilesoptional - integerThe maximum number of container log files that can be present for a container. The number must be ≥ 2.
containerLogMaxSizeMBoptional - integerThe maximum size (e.g. 10Mi) of container log file before it is rotated.
cpuCfsQuotaoptional - booleanThe default is true.
cpuCfsQuotaPeriodoptional - 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'.
cpuManagerPolicyoptional - stringThe default is 'none'. See Kubernetes CPU management policies for more information. Allowed values are 'none' and 'static'.
failSwapOnoptional - booleanIf set to true it will make the Kubelet fail to start if swap is enabled on the node.
imageGcHighThresholdoptional - integerTo disable image garbage collection, set to 100. The default is 85%
imageGcLowThresholdoptional - integerThis cannot be set higher than imageGcHighThreshold. The default is 80%
podMaxPidsoptional - integerThe maximum number of processes per pod.
topologyManagerPolicyoptional - stringFor more information see Kubernetes Topology Manager. The default is 'none'. Allowed values are 'none', 'best-effort', 'restricted', and 'single-numa-node'.
kubeletDiskTypeoptional - stringlinuxOSConfigoptionalswapFileSizeMBoptional - integerThe size in MB of a swap file that will be created on each node.
sysctlsoptionalfsAioMaxNroptional - integerSysctl setting fs.aio-max-nr.
fsFileMaxoptional - integerSysctl setting fs.file-max.
fsInotifyMaxUserWatchesoptional - integerSysctl setting fs.inotify.max_user_watches.
fsNrOpenoptional - integerSysctl setting fs.nr_open.
kernelThreadsMaxoptional - integerSysctl setting kernel.threads-max.
netCoreNetdevMaxBacklogoptional - integerSysctl setting net.core.netdev_max_backlog.
netCoreOptmemMaxoptional - integerSysctl setting net.core.optmem_max.
netCoreRmemDefaultoptional - integerSysctl setting net.core.rmem_default.
netCoreRmemMaxoptional - integerSysctl setting net.core.rmem_max.
netCoreSomaxconnoptional - integerSysctl setting net.core.somaxconn.
netCoreWmemDefaultoptional - integerSysctl setting net.core.wmem_default.
netCoreWmemMaxoptional - integerSysctl setting net.core.wmem_max.
netIpv4IpLocalPortRangeoptional - stringSysctl setting net.ipv4.ip_local_port_range.
netIpv4NeighDefaultGcThresh1optional - integerSysctl setting net.ipv4.neigh.default.gc_thresh1.
netIpv4NeighDefaultGcThresh2optional - integerSysctl setting net.ipv4.neigh.default.gc_thresh2.
netIpv4NeighDefaultGcThresh3optional - integerSysctl setting net.ipv4.neigh.default.gc_thresh3.
netIpv4TcpFinTimeoutoptional - integerSysctl setting net.ipv4.tcp_fin_timeout.
netIpv4TcpkeepaliveIntvloptional - integerSysctl setting net.ipv4.tcp_keepalive_intvl.
netIpv4TcpKeepaliveProbesoptional - integerSysctl setting net.ipv4.tcp_keepalive_probes.
netIpv4TcpKeepaliveTimeoptional - integerSysctl setting net.ipv4.tcp_keepalive_time.
netIpv4TcpMaxSynBacklogoptional - integerSysctl setting net.ipv4.tcp_max_syn_backlog.
netIpv4TcpMaxTwBucketsoptional - integerSysctl setting net.ipv4.tcp_max_tw_buckets.
netIpv4TcpTwReuseoptional - booleanSysctl setting net.ipv4.tcp_tw_reuse.
netNetfilterNfConntrackBucketsoptional - integerSysctl setting net.netfilter.nf_conntrack_buckets.
netNetfilterNfConntrackMaxoptional - integerSysctl setting net.netfilter.nf_conntrack_max.
vmMaxMapCountoptional - integerSysctl setting vm.max_map_count.
vmSwappinessoptional - integerSysctl setting vm.swappiness.
vmVfsCachePressureoptional - integerSysctl setting vm.vfs_cache_pressure.
transparentHugePageDefragoptional - stringValid values are 'always', 'defer', 'defer+madvise', 'madvise' and 'never'. The default is 'madvise'. For more information see Transparent Hugepages.
transparentHugePageEnabledoptional - stringValid values are 'always', 'madvise', and 'never'. The default is 'always'. For more information see Transparent Hugepages.
maxCountoptional - integerThe maximum number of nodes for auto-scaling
maxPodsoptional - integerThe maximum number of pods that can run on a node.
minCountoptional - integerThe minimum number of nodes for auto-scaling
modeoptional - stringnodeLabelsoptional - stringThe node labels to be persisted across all nodes in agent pool.
nodePublicIPPrefixIDoptional - stringThis is of the form: /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/publicIPPrefixes/{publicIPPrefixName}
nodeTaintsoptional - arrayThe taints added to new nodes during node pool create and scale. For example, key=value:NoSchedule.
orchestratorVersionoptional - 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.
osDiskSizeGBoptional - 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.
osDiskTypeoptional - stringosSKUoptional - stringosTypeoptional - stringpodSubnetIDoptional - 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}
powerStateoptionalcodeoptional - stringTells whether the cluster is Running or Stopped.
proximityPlacementGroupIDoptional - stringThe ID for Proximity Placement Group.
scaleDownModeoptional - stringThis also effects the cluster autoscaler behavior. If not specified, it defaults to Delete.
scaleSetEvictionPolicyoptional - stringThis cannot be specified unless the scaleSetPriority is 'Spot'. If not specified, the default is 'Delete'.
scaleSetPriorityoptional - stringThe Virtual Machine Scale Set priority. If not specified, the default is 'Regular'.
spotMaxPriceoptional - 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
tagsoptional - stringThe tags to be persisted on the agent pool virtual machine scale set.
typeoptional - stringupgradeSettingsoptionalmaxSurgeoptional - 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
vmSizeoptional - 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
vnetSubnetIDoptional - 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}
workloadRuntimeoptional - string
typerequired - 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.