From 424e973898a11a29a5243f2b520f0438a677fcae Mon Sep 17 00:00:00 2001 From: melvinlee Date: Thu, 26 Sep 2019 00:03:25 +0800 Subject: [PATCH] Example update: AKS advanced networking with multiple agent pool on VirtualMachineScaleSets. --- .../main.tf | 85 +++++++++++++++++++ .../outputs.tf | 40 +++++++++ .../variables.tf | 61 +++++++++++++ 3 files changed, 186 insertions(+) create mode 100644 examples/kubernetes/advanced-networking-multiple-agentpool/main.tf create mode 100644 examples/kubernetes/advanced-networking-multiple-agentpool/outputs.tf create mode 100644 examples/kubernetes/advanced-networking-multiple-agentpool/variables.tf diff --git a/examples/kubernetes/advanced-networking-multiple-agentpool/main.tf b/examples/kubernetes/advanced-networking-multiple-agentpool/main.tf new file mode 100644 index 000000000000..a30e57432b88 --- /dev/null +++ b/examples/kubernetes/advanced-networking-multiple-agentpool/main.tf @@ -0,0 +1,85 @@ +resource "azurerm_resource_group" "example" { + name = "${var.prefix}-anw-resources" + location = "${var.location}" +} + +resource "azurerm_route_table" "example" { + name = "${var.prefix}-routetable" + location = "${azurerm_resource_group.example.location}" + resource_group_name = "${azurerm_resource_group.example.name}" + + route { + name = "default" + address_prefix = "10.100.0.0/14" + next_hop_type = "VirtualAppliance" + next_hop_in_ip_address = "10.10.1.1" + } +} + +resource "azurerm_virtual_network" "example" { + name = "${var.prefix}-network" + location = "${azurerm_resource_group.example.location}" + resource_group_name = "${azurerm_resource_group.example.name}" + address_space = ["10.1.0.0/16"] +} + +resource "azurerm_subnet" "example" { + name = "internal" + resource_group_name = "${azurerm_resource_group.example.name}" + address_prefix = "10.1.0.0/24" + virtual_network_name = "${azurerm_virtual_network.example.name}" + + # this field is deprecated and will be removed in 2.0 - but is required until then + route_table_id = "${azurerm_route_table.example.id}" +} + +resource "azurerm_subnet_route_table_association" "example" { + subnet_id = "${azurerm_subnet.example.id}" + route_table_id = "${azurerm_route_table.example.id}" +} + +resource "azurerm_kubernetes_cluster" "example" { + name = "${var.prefix}-anw" + location = "${azurerm_resource_group.example.location}" + dns_prefix = "${var.prefix}-anw" + resource_group_name = "${azurerm_resource_group.example.name}" + + linux_profile { + admin_username = "acctestuser1" + + ssh_key { + key_data = "${file(var.public_ssh_key_path)}" + } + } + + dynamic "agent_pool_profile" { + for_each = var.agent_pools + content { + name = agent_pool_profile.value.name + count = agent_pool_profile.value.count + vm_size = agent_pool_profile.value.vm_size + os_type = agent_pool_profile.value.os_type + os_disk_size_gb = agent_pool_profile.value.os_disk_size_gb + type = "VirtualMachineScaleSets" + availability_zones = agent_pool_profile.value.availability_zones + enable_auto_scaling = agent_pool_profile.value.enable_auto_scaling + min_count = agent_pool_profile.value.min_count + max_count = agent_pool_profile.value.max_count + max_pods = agent_pool_profile.value.max_pods + + # Required for advanced networking + vnet_subnet_id = "${azurerm_subnet.example.id}" + } + } + + service_principal { + client_id = "${var.kubernetes_client_id}" + client_secret = "${var.kubernetes_client_secret}" + } + + network_profile { + network_plugin = "azure" + # Required for availability zones + load_balancer_sku = "standard" + } +} diff --git a/examples/kubernetes/advanced-networking-multiple-agentpool/outputs.tf b/examples/kubernetes/advanced-networking-multiple-agentpool/outputs.tf new file mode 100644 index 000000000000..7c675806179b --- /dev/null +++ b/examples/kubernetes/advanced-networking-multiple-agentpool/outputs.tf @@ -0,0 +1,40 @@ +output "subnet_id" { + value = "${azurerm_kubernetes_cluster.example.agent_pool_profile.0.vnet_subnet_id}" +} + +output "network_plugin" { + value = "${azurerm_kubernetes_cluster.example.network_profile.0.network_plugin}" +} + +output "service_cidr" { + value = "${azurerm_kubernetes_cluster.example.network_profile.0.service_cidr}" +} + +output "dns_service_ip" { + value = "${azurerm_kubernetes_cluster.example.network_profile.0.dns_service_ip}" +} + +output "docker_bridge_cidr" { + value = "${azurerm_kubernetes_cluster.example.network_profile.0.docker_bridge_cidr}" +} + +output "pod_cidr" { + value = "${azurerm_kubernetes_cluster.example.network_profile.0.pod_cidr}" +} + +output "kube_config_raw" { + value = azurerm_kubernetes_cluster.example.kube_config_raw + sensitive = true +} + +output "config" { + value = < ~/.kube/aksconfig +$ export KUBECONFIG=~/.kube/aksconfig + +CONFIGURE + +} \ No newline at end of file diff --git a/examples/kubernetes/advanced-networking-multiple-agentpool/variables.tf b/examples/kubernetes/advanced-networking-multiple-agentpool/variables.tf new file mode 100644 index 000000000000..f3ea35278e29 --- /dev/null +++ b/examples/kubernetes/advanced-networking-multiple-agentpool/variables.tf @@ -0,0 +1,61 @@ +variable "prefix" { + description = "A prefix used for all resources in this example" +} + +variable "location" { + description = "The Azure Region in which all resources in this example should be provisioned" +} + +variable "kubernetes_client_id" { + description = "The Client ID for the Service Principal to use for this Managed Kubernetes Cluster" +} + +variable "kubernetes_client_secret" { + description = "The Client Secret for the Service Principal to use for this Managed Kubernetes Cluster" +} + +variable "public_ssh_key_path" { + description = "The Path at which your Public SSH Key is located. Defaults to ~/.ssh/id_rsa.pub" + default = "~/.ssh/id_rsa.pub" +} + +variable "agent_pools" { + description = "(Optional) List of agent_pools profile for multiple node pools" + type = list(object({ + name = string + count = number + vm_size = string + os_type = string + os_disk_size_gb = number + max_pods = number + availability_zones = list(number) + enable_auto_scaling = bool + min_count = number + max_count = number + })) + + default = [{ + name = "pool1" + count = 1 + vm_size = "Standard_D2s_v3" + os_type = "Linux" + os_disk_size_gb = 30 + max_pods = 30 + availability_zones = [1, 2, 3] + enable_auto_scaling = true + min_count = 1 + max_count = 3 + }, + { + name = "pool2" + count = 1 + vm_size = "Standard_D2s_v3" + os_type = "Linux" + os_disk_size_gb = 30 + max_pods = 30 + availability_zones = [1, 2, 3] + enable_auto_scaling = true + min_count = 1 + max_count = 3 +}] +}