Skip to content

Commit 773a10c

Browse files
bamaralfyupwei68
andauthored
Edit the 'default_node_pool' and 'network_profile' config blocks (Azure#80)
* Edit main.tf and variables.tf * Edit variables references * Edit the test/fixture/main.tf * Rename variable * Add net_profile_pod_cidr and net_profile_service_cidr vars * Add net_profile_pod_cidr and net_profile_service_cidr vars * Rename variable * Edit the 'default_node_pool' config * Update main.tf reverse changes to break users * Update main.tf integrate the enhancement fields into module "aks" * Update variables.tf set some defaults to null when there is no definition from AzureRm Provider side * Update README.md * Update README.md * Edit the README.md * Update main.tf format * Update README.md Kubernete version > 19.0 doesn't allow enable dashboard * Update README.md node name should be less than 12 characters Co-authored-by: Yuping Wei <56525716+yupwei68@users.noreply.github.com>
1 parent 8e41175 commit 773a10c

File tree

4 files changed

+139
-13
lines changed

4 files changed

+139
-13
lines changed

README.md

+19-2
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,34 @@ module "aks" {
4141
network_plugin = "azure"
4242
vnet_subnet_id = module.network.vnet_subnets[0]
4343
os_disk_size_gb = 50
44-
enable_kube_dashboard = true
45-
enable_azure_policy = true
4644
sku_tier = "Paid" # defaults to Free
4745
enable_role_based_access_control = true
4846
rbac_aad_admin_group_object_ids = [data.azuread_group.aks_cluster_admins.id]
4947
rbac_aad_managed = true
5048
private_cluster_enabled = true # default value
49+
enable_http_application_routing = true
50+
enable_azure_policy = true
5151
enable_auto_scaling = true
5252
agents_min_count = 1
5353
agents_max_count = 2
5454
agents_count = null # Please set `agents_count` `null` while `enable_auto_scaling` is `true` to avoid possible `agents_count` changes.
55+
agents_max_pods = 100
56+
agents_pool_name = "exnodepool"
57+
agents_availability_zones = ["1", "2"]
58+
agents_type = "VirtualMachineScaleSets"
59+
60+
agents_labels = {
61+
"nodepool" : "defaultnodepool"
62+
}
63+
64+
agents_tags = {
65+
"Agent" : "defaultnodepoolagent"
66+
}
67+
68+
network_policy = "azure"
69+
net_profile_dns_service_ip = "10.0.0.10"
70+
net_profile_docker_bridge_cidr = "170.10.0.1/16"
71+
net_profile_service_cidr = "10.0.0.0/16"
5572
5673
depends_on = [module.network]
5774
}

main.tf

+23-10
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ module "ssh-key" {
99

1010
resource "azurerm_kubernetes_cluster" "main" {
1111
name = "${var.prefix}-aks"
12+
kubernetes_version = var.kubernetes_version
1213
location = data.azurerm_resource_group.main.location
1314
resource_group_name = data.azurerm_resource_group.main.name
1415
dns_prefix = var.prefix
@@ -25,15 +26,21 @@ resource "azurerm_kubernetes_cluster" "main" {
2526
}
2627

2728
default_node_pool {
28-
orchestrator_version = var.orchestrator_version
29-
name = "nodepool"
30-
node_count = var.agents_count
31-
vm_size = var.agents_size
32-
os_disk_size_gb = var.os_disk_size_gb
33-
vnet_subnet_id = var.vnet_subnet_id
34-
enable_auto_scaling = var.enable_auto_scaling
35-
max_count = var.enable_auto_scaling ? var.agents_max_count : null
36-
min_count = var.enable_auto_scaling ? var.agents_min_count : null
29+
orchestrator_version = var.orchestrator_version
30+
name = var.agents_pool_name
31+
node_count = var.agents_count
32+
vm_size = var.agents_size
33+
os_disk_size_gb = var.os_disk_size_gb
34+
vnet_subnet_id = var.vnet_subnet_id
35+
enable_auto_scaling = var.enable_auto_scaling
36+
max_count = var.enable_auto_scaling ? var.agents_max_count : null
37+
min_count = var.enable_auto_scaling ? var.agents_min_count : null
38+
enable_node_public_ip = var.enable_node_public_ip
39+
availability_zones = var.agents_availability_zones
40+
node_labels = var.agents_labels
41+
type = var.agents_type
42+
tags = merge(var.tags, var.agents_tags)
43+
max_pods = var.agents_max_pods
3744
}
3845

3946
dynamic "service_principal" {
@@ -102,7 +109,13 @@ resource "azurerm_kubernetes_cluster" "main" {
102109
}
103110

104111
network_profile {
105-
network_plugin = var.network_plugin
112+
network_plugin = var.network_plugin
113+
network_policy = var.network_policy
114+
dns_service_ip = var.net_profile_dns_service_ip
115+
docker_bridge_cidr = var.net_profile_docker_bridge_cidr
116+
outbound_type = var.net_profile_outbound_type
117+
pod_cidr = var.net_profile_pod_cidr
118+
service_cidr = var.net_profile_service_cidr
106119
}
107120

108121
tags = var.tags

test/fixture/main.tf

+19-1
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,28 @@ module "aks" {
3838
enable_http_application_routing = true
3939
enable_azure_policy = true
4040
sku_tier = "Paid"
41-
enable_kube_dashboard = true
4241
private_cluster_enabled = true
4342
enable_auto_scaling = true
4443
agents_min_count = 1
4544
agents_max_count = 2
4645
agents_count = null
46+
agents_max_pods = 100
47+
agents_pool_name = "testnodepool"
48+
agents_availability_zones = ["1", "2"]
49+
agents_type = "VirtualMachineScaleSets"
50+
51+
agents_labels = {
52+
"node1" : "label1"
53+
}
54+
55+
agents_tags = {
56+
"Agent" : "agentTag"
57+
}
58+
59+
network_policy = "azure"
60+
net_profile_dns_service_ip = "10.0.0.10"
61+
net_profile_docker_bridge_cidr = "170.10.0.1/16"
62+
net_profile_service_cidr = "10.0.0.0/16"
4763

4864
depends_on = [azurerm_resource_group.main]
4965
}
@@ -53,5 +69,7 @@ module "aks_without_monitor" {
5369
prefix = "prefix2-${random_id.prefix.hex}"
5470
resource_group_name = azurerm_resource_group.main.name
5571
enable_log_analytics_workspace = false
72+
enable_kube_dashboard = false
73+
net_profile_pod_cidr = "10.1.0.0/16"
5674
depends_on = [azurerm_resource_group.main]
5775
}

variables.tf

+78
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,42 @@ variable "network_plugin" {
152152
default = "kubenet"
153153
}
154154

155+
variable "network_policy" {
156+
description = " (Optional) Sets up network policy to be used with Azure CNI. Network policy allows us to control the traffic flow between pods. Currently supported values are calico and azure. Changing this forces a new resource to be created."
157+
type = string
158+
default = null
159+
}
160+
161+
variable "net_profile_dns_service_ip" {
162+
description = "(Optional) IP address within the Kubernetes service address range that will be used by cluster service discovery (kube-dns). Changing this forces a new resource to be created."
163+
type = string
164+
default = null
165+
}
166+
167+
variable "net_profile_docker_bridge_cidr" {
168+
description = "(Optional) IP address (in CIDR notation) used as the Docker bridge IP address on nodes. Changing this forces a new resource to be created."
169+
type = string
170+
default = null
171+
}
172+
173+
variable "net_profile_outbound_type" {
174+
description = "(Optional) The outbound (egress) routing method which should be used for this Kubernetes Cluster. Possible values are loadBalancer and userDefinedRouting. Defaults to loadBalancer."
175+
type = string
176+
default = "loadBalancer"
177+
}
178+
179+
variable "net_profile_pod_cidr" {
180+
description = " (Optional) The CIDR to use for pod IP addresses. This field can only be set when network_plugin is set to kubenet. Changing this forces a new resource to be created."
181+
type = string
182+
default = null
183+
}
184+
185+
variable "net_profile_service_cidr" {
186+
description = "(Optional) The Network Range used by the Kubernetes service. Changing this forces a new resource to be created."
187+
type = string
188+
default = null
189+
}
190+
155191
variable "kubernetes_version" {
156192
description = "Specify which Kubernetes release to use. The default used is the latest Kubernetes version available in the region"
157193
type = string
@@ -181,3 +217,45 @@ variable "agents_min_count" {
181217
description = "Minimum number of nodes in a pool"
182218
default = null
183219
}
220+
221+
variable "agents_pool_name" {
222+
description = "The default Azure AKS agentpool (nodepool) name."
223+
type = string
224+
default = "nodepool"
225+
}
226+
227+
variable "enable_node_public_ip" {
228+
description = "(Optional) Should nodes in this Node Pool have a Public IP Address? Defaults to false."
229+
type = bool
230+
default = false
231+
}
232+
233+
variable "agents_availability_zones" {
234+
description = "(Optional) A list of Availability Zones across which the Node Pool should be spread. Changing this forces a new resource to be created."
235+
type = list(string)
236+
default = null
237+
}
238+
239+
variable "agents_labels" {
240+
description = "(Optional) A map of Kubernetes labels which should be applied to nodes in the Default Node Pool. Changing this forces a new resource to be created."
241+
type = map(string)
242+
default = {}
243+
}
244+
245+
variable "agents_type" {
246+
description = "(Optional) The type of Node Pool which should be created. Possible values are AvailabilitySet and VirtualMachineScaleSets. Defaults to VirtualMachineScaleSets."
247+
type = string
248+
default = "VirtualMachineScaleSets"
249+
}
250+
251+
variable "agents_tags" {
252+
description = "(Optional) A mapping of tags to assign to the Node Pool."
253+
type = map(string)
254+
default = {}
255+
}
256+
257+
variable "agents_max_pods" {
258+
description = "(Optional) The maximum number of pods that can run on each agent. Changing this forces a new resource to be created."
259+
type = number
260+
default = null
261+
}

0 commit comments

Comments
 (0)