Skip to content

Commit

Permalink
Merge pull request #4436 from melvinlee/master
Browse files Browse the repository at this point in the history
Example update: AKS advanced networking with multiple agent pool on VMSS
  • Loading branch information
tombuildsstuff authored Oct 1, 2019
2 parents b0f9a68 + 424e973 commit 235a7a9
Show file tree
Hide file tree
Showing 3 changed files with 186 additions and 0 deletions.
85 changes: 85 additions & 0 deletions examples/kubernetes/advanced-networking-multiple-agentpool/main.tf
Original file line number Diff line number Diff line change
@@ -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"
}
}
Original file line number Diff line number Diff line change
@@ -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 = <<CONFIGURE
Run the following commands to configure kubernetes clients:
$ terraform output kube_config_raw > ~/.kube/aksconfig
$ export KUBECONFIG=~/.kube/aksconfig
CONFIGURE

}
Original file line number Diff line number Diff line change
@@ -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
}]
}

0 comments on commit 235a7a9

Please sign in to comment.