Skip to content

Commit

Permalink
PLAT-5257: Create a nodepool per zone (#29)
Browse files Browse the repository at this point in the history
* PLAT-5257: Create a nodepool per zone
* PLAT-5257: Dedicated system node pool
  • Loading branch information
miguelhar authored Aug 22, 2022
1 parent f213952 commit 56873b1
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 41 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
.terraform
.terraform
**.terraform.lock.hcl
**terraform.tfstate
**terraform.tfstate.backup
**kubeconfig
83 changes: 44 additions & 39 deletions aks.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,21 @@ locals {
for node_pool, attrs in var.node_pools :
node_pool => merge(attrs, lookup(var.node_pool_overrides, node_pool, {}))
}

zonal_node_pools = flatten([for name, spec in local.node_pools : [
for zone in spec.zones :
{
node_pool_zone = zone
node_pool_name = name
node_pool_spec = spec
}
]
])
}

data "azurerm_kubernetes_service_versions" "selected" {
location = data.azurerm_resource_group.aks.location
version_prefix = var.kubernetes_version
include_preview = true
location = data.azurerm_resource_group.aks.location
version_prefix = var.kubernetes_version
}

resource "azurerm_kubernetes_cluster" "aks" {
Expand All @@ -34,21 +43,19 @@ resource "azurerm_kubernetes_cluster" "aks" {
api_server_authorized_ip_ranges = var.api_server_authorized_ip_ranges

default_node_pool {
enable_node_public_ip = local.node_pools.platform.enable_node_public_ip
name = "platform"
node_count = local.node_pools.platform.initial_count
node_labels = local.node_pools.platform.node_labels
vm_size = local.node_pools.platform.vm_size
zones = local.node_pools.platform.zones
os_disk_size_gb = local.node_pools.platform.os_disk_size_gb
node_taints = local.node_pools.platform.node_taints
enable_auto_scaling = local.node_pools.platform.enable_auto_scaling
min_count = local.node_pools.platform.min_count
max_count = local.node_pools.platform.max_count
max_pods = local.node_pools.platform.max_pods
tags = var.tags
enable_node_public_ip = false
only_critical_addons_enabled = true
name = "system"
node_count = 1
vm_size = "standard_ds4_v2"
zones = ["1", "2", "3"]
os_disk_size_gb = 128
enable_auto_scaling = true
min_count = 1
max_count = 6
max_pods = 60
tags = var.tags
}

identity {
type = "SystemAssigned"
}
Expand Down Expand Up @@ -77,31 +84,29 @@ resource "azurerm_kubernetes_cluster" "aks" {
}
}

resource "azurerm_kubernetes_cluster_node_pool" "aks" {
lifecycle {
ignore_changes = [node_count, max_count, tags]
}

for_each = {
# Create all node pools except for 'platform' because it is the AKS default
for key, value in local.node_pools :
key => value
if key != "platform"
}

enable_node_public_ip = each.value.enable_node_public_ip
resource "azurerm_kubernetes_cluster_node_pool" "aks" {
for_each = { for ng in local.zonal_node_pools : "${ng.node_pool_name}${ng.node_pool_zone}" => ng }

enable_node_public_ip = each.value.node_pool_spec.enable_node_public_ip
kubernetes_cluster_id = azurerm_kubernetes_cluster.aks.id
name = each.key
node_count = each.value.initial_count
vm_size = each.value.vm_size
zones = each.value.zones
os_disk_size_gb = each.value.os_disk_size_gb
os_type = each.value.node_os
node_labels = each.value.node_labels
node_taints = each.value.node_taints
enable_auto_scaling = each.value.enable_auto_scaling
min_count = each.value.min_count
max_count = each.value.max_count
max_pods = each.value.max_pods
node_count = each.value.node_pool_spec.initial_count
vm_size = each.value.node_pool_spec.vm_size
zones = [each.value.node_pool_zone]
os_disk_size_gb = each.value.node_pool_spec.os_disk_size_gb
os_type = each.value.node_pool_spec.node_os
node_labels = each.value.node_pool_spec.node_labels
node_taints = each.value.node_pool_spec.node_taints
enable_auto_scaling = each.value.node_pool_spec.enable_auto_scaling
min_count = each.value.node_pool_spec.min_count
max_count = each.value.node_pool_spec.max_count
max_pods = each.value.node_pool_spec.max_pods
tags = var.tags

lifecycle {
ignore_changes = [node_count, max_count, tags]
}

}
2 changes: 1 addition & 1 deletion tests/test.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ provider "azurerm" {
}

variable "api_server_authorized_ip_ranges" {
type = list(string)
type = list(string)
}

variable "tags" {
Expand Down

0 comments on commit 56873b1

Please sign in to comment.