Skip to content

Commit 87a00f5

Browse files
authored
feat!: (IAC-1009) Add support for network plugin mode overlay (#360)
1 parent 9e907cd commit 87a00f5

File tree

5 files changed

+33
-17
lines changed

5 files changed

+33
-17
lines changed

docs/CONFIG-VARS.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ az vm image terms accept --urn Canonical:0001-com-ubuntu-pro-focal-fips:pro-fips
102102
| subnets | Subnets to be created and their settings | map(object) | *check below* | This variable is ignored when subnet_names is set (AKA bring your own subnets). All defined subnets must exist within the vnet address space. |
103103
| cluster_egress_type | The outbound (egress) routing method to be used for this Kubernetes Cluster | string | "loadBalancer" | Possible values: <ul><li>`loadBalancer`<li>`userDefinedRouting`</ul> By default, AKS will create and use a [loadbalancer](https://docs.microsoft.com/en-us/azure/aks/load-balancer-standard) for outgoing connections.<p>Set to `userDefinedRouting` when using your own network [egress](https://docs.microsoft.com/en-us/azure/aks/egress-outboundtype).|
104104
| aks_network_plugin | Network plugin to use for networking. Currently supported values are `azure` and `kubenet`| string | `kubenet`| For details see Azure's documentation on: [configure kubenet](https://docs.microsoft.com/en-us/azure/aks/configure-kubenet), [Configure Azure CNI](https://learn.microsoft.com/en-us/azure/aks/configure-azure-cni).<br>**Note**: To support Azure CNI your Subnet must be large enough to accommodate the nodes, pods, and all Kubernetes and Azure resources that might be provisioned in your cluster.<br>To calculate the minimum subnet size including an additional node for upgrade operations use formula: `(number of nodes + 1) + ((number of nodes + 1) * maximum pods per node that you configure)` <br>Example for a 5 node cluster: `(5) + (5 * 110) = 555 (/22 or larger)`|
105-
| aks_network_policy | Sets up network policy to be used with Azure CNI. Network policy allows to control the traffic flow between pods. Currently supported values are `calico` and `azure`.| string | `azure`| Network policy `azure` is only supported for `aks_network_plugin = azure` and network policy `calico` is supported for both `aks_network_plugin` values `azure` and `kubenet`. |
106-
105+
| aks_network_policy | Sets up network policy to be used with Azure CNI. Network policy allows to control the traffic flow between pods. Currently supported values are `calico` and `azure`.| string | null | Network policy `azure` is only supported for `aks_network_plugin = azure` and network policy `calico` is supported for both `aks_network_plugin` values `azure` and `kubenet`. |
106+
| aks_network_plugin_mode | Specifies the network plugin mode used for building the Kubernetes network. Possible value is `overlay`.| string | null | When `aks_network_plugin_mode` is set to `overlay` , the `aks_network_plugin` field can only be set to `azure`. For details see Azure's documentation on: [Configure Azure CNI Overlay networking](https://learn.microsoft.com/en-us/azure/aks/azure-cni-overlay).|
107107

108108
The default values for the `subnets` variable are as follows:
109109

main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ module "aks" {
153153
aks_log_analytics_workspace_id = var.create_aks_azure_monitor ? azurerm_log_analytics_workspace.viya4[0].id : null
154154
aks_network_plugin = var.aks_network_plugin
155155
aks_network_policy = var.aks_network_policy
156+
aks_network_plugin_mode = var.aks_network_plugin_mode
156157
aks_dns_service_ip = var.aks_dns_service_ip
157158
aks_docker_bridge_cidr = var.aks_docker_bridge_cidr
158159
cluster_egress_type = local.cluster_egress_type

modules/azure_aks/main.tf

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ resource "azurerm_kubernetes_cluster" "aks" {
2121
private_dns_zone_id = var.aks_private_cluster && var.aks_cluster_private_dns_zone_id != "" ? var.aks_cluster_private_dns_zone_id : (var.aks_private_cluster ? "System" : null)
2222

2323
network_profile {
24-
network_plugin = var.aks_network_plugin
25-
network_policy = var.aks_network_plugin == "kubenet" && var.aks_network_policy == "azure" ? null : var.aks_network_policy
26-
2724
# Docs on AKS Advanced Networking config
2825
# https://docs.microsoft.com/en-us/azure/architecture/aws-professional/networking
2926
# https://docs.microsoft.com/en-us/azure/virtual-network/virtual-network-vnet-plan-design-arm
@@ -32,12 +29,15 @@ resource "azurerm_kubernetes_cluster" "aks" {
3229
# https://docs.microsoft.com/en-us/azure/aks/load-balancer-standard
3330
# https://docs.microsoft.com/en-us/azure/aks/egress-outboundtype
3431

35-
service_cidr = var.aks_service_cidr
36-
dns_service_ip = var.aks_dns_service_ip
37-
pod_cidr = var.aks_network_plugin == "kubenet" ? var.aks_pod_cidr : null
38-
docker_bridge_cidr = var.aks_docker_bridge_cidr
39-
outbound_type = var.cluster_egress_type
40-
load_balancer_sku = "standard"
32+
network_plugin = var.aks_network_plugin
33+
network_policy = var.aks_network_policy
34+
network_plugin_mode = var.aks_network_plugin_mode
35+
service_cidr = var.aks_service_cidr
36+
dns_service_ip = var.aks_dns_service_ip
37+
pod_cidr = var.aks_network_plugin == "kubenet" ? var.aks_pod_cidr : null
38+
docker_bridge_cidr = var.aks_docker_bridge_cidr
39+
outbound_type = var.cluster_egress_type
40+
load_balancer_sku = "standard"
4141
}
4242

4343
dynamic "linux_profile" {
@@ -102,6 +102,14 @@ resource "azurerm_kubernetes_cluster" "aks" {
102102

103103
lifecycle {
104104
ignore_changes = [default_node_pool[0].node_count]
105+
precondition {
106+
condition = var.aks_network_policy != "azure" || var.aks_network_plugin == "azure"
107+
error_message = "When aks_network_policy is set to `azure`, the aks_network_plugin field can only be set to `azure`."
108+
}
109+
precondition {
110+
condition = var.aks_network_plugin_mode != "overlay" || var.aks_network_plugin == "azure"
111+
error_message = "When network_plugin_mode is set to `overlay`, the aks_network_plugin field can only be set to `azure`."
112+
}
105113
}
106114

107115
tags = var.aks_cluster_tags

modules/azure_aks/variables.tf

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,13 @@ variable "aks_network_plugin" {
133133
variable "aks_network_policy" {
134134
description = "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."
135135
type = string
136-
default = "azure"
136+
default = null
137+
}
138+
139+
variable "aks_network_plugin_mode" {
140+
description = "Specifies the network plugin mode used for building the Kubernetes network. Possible value is `overlay`. Changing this forces a new resource to be created."
141+
type = string
142+
default = null
137143
}
138144

139145
variable "aks_dns_service_ip" {

variables.tf

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,13 @@ variable "aks_network_plugin" {
169169
variable "aks_network_policy" {
170170
description = "Sets up network policy to be used with Azure CNI. Network policy allows control of the traffic flow between pods. Currently supported values are calico and azure. Changing this forces a new resource to be created."
171171
type = string
172-
default = "azure"
172+
default = null
173+
}
173174

174-
validation {
175-
condition = contains(["azure", "calico"], var.aks_network_policy)
176-
error_message = "Error: Currently the supported values are 'calico' and 'azure'."
177-
}
175+
variable "aks_network_plugin_mode" {
176+
description = "Specifies the network plugin mode used for building the Kubernetes network. Possible value is `overlay`. Changing this forces a new resource to be created."
177+
type = string
178+
default = null
178179
}
179180

180181
variable "aks_dns_service_ip" {

0 commit comments

Comments
 (0)