Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Support more flexible nodes and deployment #8

Merged
merged 2 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ module "load_balancer" {
}

module "database" {
count = var.create_database ? 1 : 0

source = "./modules/database"

deployment_name = var.deployment_name
Expand Down Expand Up @@ -105,9 +107,12 @@ module "aks" {

max_pods = var.max_pods
node_pool_node_count = var.node_pool_node_count
min_node_count = var.min_node_count
max_node_count = var.max_node_count
node_pool_vm_size = var.node_pool_vm_size
node_pool_name = var.node_pool_name
sku_tier = var.aks_sku_tier
service_cidr = var.aks_service_cidr
dns_service_ip = var.aks_dns_service_ip
custom_node_pools = var.custom_node_pools
}
38 changes: 36 additions & 2 deletions modules/aks/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ resource "azurerm_kubernetes_cluster" "default" {
vnet_subnet_id = var.aks_subnet.id

enable_auto_scaling = true
max_count = 2
min_count = 1
max_count = var.max_node_count
min_count = var.min_node_count
node_count = var.node_pool_node_count

upgrade_settings {
Expand Down Expand Up @@ -55,6 +55,40 @@ resource "azurerm_kubernetes_cluster" "default" {
}
}

resource "azurerm_kubernetes_cluster_node_pool" "custom_node_pools" {
for_each = { for pool in var.custom_node_pools : pool.name => pool if pool.enabled }

# Name must begin with a lowercase letter, contain only lowercase letters and numbers and be between 1 and 12 characters in length
name = replace(each.value.name, "-", "")
kubernetes_cluster_id = azurerm_kubernetes_cluster.default.id
vnet_subnet_id = var.aks_subnet.id
vm_size = each.value.vm_size
os_disk_type = each.value.disk_type
os_disk_size_gb = each.value.disk_size_gb

enable_auto_scaling = true
node_count = each.value.initial_node_count
min_count = each.value.min_node_count
max_count = each.value.max_node_count
eviction_policy = each.value.spot ? "Delete" : null

priority = each.value.spot ? "Spot" : "Regular"

# Upgrade-specific settings if max_surge is defined. Spot pools can't set max surge
dynamic "upgrade_settings" {
for_each = each.value.max_surge != null ? [1] : []
content {
max_surge = each.value.max_surge
}
}

node_taints = [
for taint in each.value.taints : "${taint.key}=${taint.value}:${taint.effect}"
]

tags = var.tags
}

locals {
ingress_gateway_principal_id = azurerm_kubernetes_cluster.default.ingress_application_gateway.0.ingress_application_gateway_identity.0.object_id
}
Expand Down
30 changes: 30 additions & 0 deletions modules/aks/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ variable "node_pool_node_count" {
type = number
}

variable "min_node_count" {
type = number
}

variable "max_node_count" {
type = number
}

variable "sku_tier" {
type = string
default = "Free"
Expand All @@ -88,4 +96,26 @@ variable "service_cidr" {
variable "dns_service_ip" {
type = string
description = "The IP address for the DNS service"
}

variable "custom_node_pools" {
type = list(object({
name = string
enabled = bool
initial_node_count = number
vm_size = string
disk_size_gb = number
disk_type = string
taints = list(object({
key = string
value = string
effect = string
}))
spot = bool
min_node_count = number
max_node_count = number
max_surge = number
}))
description = "Dynamic extra node pools"
default = []
}
8 changes: 4 additions & 4 deletions outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ output "load_balancer_ips" {
}

output "postgres_database_name" {
value = module.database.postgres_database_name
value = coalesce(concat(module.database[*].postgres_database_name, ["notset"])...)
}

output "postgres_password" {
value = module.database.postgres_password
value = coalesce(concat(module.database[*].postgres_password, ["notset"])...)
}

output "postgres_host" {
value = module.database.postgres_host
value = coalesce(concat(module.database[*].postgres_host, ["notset"])...)
}

output "postgres_username" {
value = module.database.postgres_username
value = coalesce(concat(module.database[*].postgres_username, ["notset"])...)
}

output "azure_blob_account_name" {
Expand Down
38 changes: 38 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ variable "ssl_cert_name" {
# ┃┃┣━┫ ┃ ┣━┫┣┻┓┣━┫┗━┓┣╸
# ╺┻┛╹ ╹ ╹ ╹ ╹┗━┛╹ ╹┗━┛┗━╸

variable "create_database" {
type = bool
default = true
description = "Flag to toggle PostgreSQL database creation"
}

variable "database_username" {
type = string
default = "datafold"
Expand Down Expand Up @@ -178,6 +184,16 @@ variable "node_pool_node_count" {
default = 1
}

variable "min_node_count" {
type = number
default = 1
}

variable "max_node_count" {
type = number
default = 2
}

variable "node_pool_vm_size" {
description = "The size of the VMs in the pool"
type = string
Expand Down Expand Up @@ -208,6 +224,28 @@ variable "aks_dns_service_ip" {
default = "172.16.0.10"
}

variable "custom_node_pools" {
type = list(object({
name = string
enabled = bool
initial_node_count = number
vm_size = string
disk_size_gb = number
disk_type = string
taints = list(object({
key = string
value = string
effect = string
}))
spot = bool
min_node_count = number
max_node_count = number
max_surge = number
}))
description = "Dynamic extra node pools"
default = []
}

# ┏━╸┏━╸┏━┓╺┳╸
# ┃ ┣╸ ┣┳┛ ┃
# ┗━╸┗━╸╹┗╸ ╹
Expand Down
Loading