项目作者: melvinlee

项目描述 :
Azure Terraform for creating Azure Kubernetes Services with Advanced Networking
高级语言: HCL
项目地址: git://github.com/melvinlee/terraform-az-aks.git
创建时间: 2019-09-22T15:04:01Z
项目社区:https://github.com/melvinlee/terraform-az-aks

开源协议:

下载


Create Azure Kubernetes Services with Advanced Networking

Create Azure Kubernetes Services

  • Advanced Networking
  • Multiple Node pools
  • Diagnostics logging for master node

Reference the module to a specific version (recommended):

  1. module "aks" {
  2. source = "git://github.com/melvinlee/terraform-az-aks.git?ref=v0.1"
  3. aks_rg = var.aks_rg
  4. location = var.location
  5. ...
  6. }

Or get the latest version

  1. source = "git://github.com/melvinlee/terraform-az-aks.git?ref=latest"

Parameters

aks_rg

  1. variable "aks_rg" {
  2. description = "(Required) Name of the resource group where to create the aks"
  3. type = string
  4. }

location

  1. variable "location" {
  2. description = "(Required) Define the region where the resource groups will be created"
  3. type = string
  4. }

name

  1. variable "name" {
  2. description = "(Required) The name of the Managed Kubernetes Cluster to create."
  3. type = string
  4. }

aks_node_rg

  1. variable "aks_node_rg" {
  2. description = "(Optional) The name of the Resource Group where the the Kubernetes Nodes should exist."
  3. type = string
  4. default = null
  5. }

agent_pool_subnet_id

  1. variable "agent_pool_subnet_id" {
  2. description = "(Required) The ID of the Subnet where the Agents in the Pool should be provisioned."
  3. }

agent_pools

  1. variable "agent_pools" {
  2. description = "(Optional) List of agent_pools profile for multiple node pools"
  3. type = list(object({
  4. name = string
  5. count = number
  6. vm_size = string
  7. os_type = string
  8. os_disk_size_gb = number
  9. type = string
  10. max_pods = number
  11. availability_zones = list(number)
  12. enable_auto_scaling = bool
  13. min_count = number
  14. max_count = number
  15. }))
  16. default = [{
  17. name = "default"
  18. count = 1
  19. vm_size = "Standard_D2s_v3"
  20. os_type = "Linux"
  21. os_disk_size_gb = 50
  22. type = "VirtualMachineScaleSets"
  23. max_pods = 30
  24. availability_zones = [1, 2, 3]
  25. enable_auto_scaling = true
  26. min_count = 1
  27. max_count = 3
  28. }]
  29. }

Example

Multiple node pools with different VM type (SKU)

  1. agent_pools = [{
  2. name = "pool1"
  3. count = 1
  4. vm_size = "Standard_D2s_v3"
  5. os_type = "Linux"
  6. os_disk_size_gb = 50
  7. max_pods = 30
  8. type = "VirtualMachineScaleSets"
  9. availability_zones = [1, 2, 3]
  10. enable_auto_scaling = true
  11. min_count = 1
  12. max_count = 3
  13. },
  14. {
  15. name = "pool2"
  16. count = 1
  17. vm_size = "Standard_D4s_v3"
  18. os_type = "Linux"
  19. os_disk_size_gb = 30
  20. max_pods = 30
  21. type = "VirtualMachineScaleSets"
  22. availability_zones = [1, 2, 3]
  23. enable_auto_scaling = true
  24. min_count = 1
  25. max_count = 3
  26. }]

linux_admin_username

  1. variable "linux_admin_username" {
  2. description = "(Optional) User name for authentication to the Kubernetes linux agent virtual machines in the cluster."
  3. type = "string"
  4. default = "azureuser"
  5. }

kubernetes_version

  1. variable "kubernetes_version" {
  2. description = "(Optional) Version of Kubernetes specified when creating the AKS managed cluster"
  3. default = ""
  4. }

tags

  1. variable "tags" {
  2. description = "(Required) Map of tags for the deployment"
  3. }

Example

  1. tags = {
  2. environment = "development"
  3. creationSource = "terraform"
  4. department = "ops"
  5. costCenter = "8000"
  6. }

addon_profile

  1. variable "addon_profile" {
  2. description = "(Optional) AddOn Profile block."
  3. default = {
  4. oms_agent_enabled = false # Enable Container Monitoring
  5. http_application_routing_enabled = false # Disable HTTP Application Routing
  6. kube_dashboard_enabled = false # Disable Kubernetes Dashboard
  7. }
  8. }

log_analytics_workspace

  1. variable "log_analytics_workspace" {
  2. description = "(Optional) The ID of the Log Analytics Workspace which the OMS Agent should send data to."
  3. default = null
  4. }

network_profile

  1. variable "network_profile" {
  2. description = "(Optional) Sets up network profile for Advanced Networking."
  3. default = {
  4. # Use azure-cni for advanced networking
  5. network_plugin = "azure"
  6. # Sets up network policy to be used with Azure CNI. Currently supported values are calico and azure."
  7. network_policy = "azure"
  8. service_cidr = "10.100.0.0/16"
  9. dns_service_ip = "10.100.0.10"
  10. docker_bridge_cidr = "172.17.0.1/16"
  11. # Specifies the SKU of the Load Balancer used for this Kubernetes Cluster. Use standard for when enable agent_pools availability_zones.
  12. load_balancer_sku = "Standard"
  13. }
  14. }

service_principal

  1. variable "service_principal" {
  2. description = "(Required) The Service Principal to create aks."
  3. type = object({
  4. client_id = string
  5. client_secret = string
  6. })
  7. }

Example

  1. service_principal = {
  2. client_id = "00000000-0000-0000-0000-000000000000"
  3. client_secret = "00000000-0000-0000-0000-000000000000"
  4. }

diagnostics_log_category

  1. variable "diagnostics_logs_map" {
  2. description = "(Optional) Send the logs generated by AKS master node to diagnostics"
  3. default = {
  4. log = [
  5. #["Category name", "Diagnostics Enabled", "Retention Enabled", Retention period]
  6. ["kube-apiserver", true, true, 30],
  7. ["kube-controller-manager", true, true, 30],
  8. ["kube-scheduler", true, true, 30],
  9. ["kube-audit", true, true, 30],
  10. ["cluster-autoscaler", true, true, 30]
  11. ]
  12. metric = [
  13. ["AllMetrics", true, true, 30],
  14. ]
  15. }
  16. }

diagnostics_map

  1. variable "diagnostics_map" {
  2. description = "(Optional) Storage Account and Event Hub data for the AKS diagnostics"
  3. default = {
  4. log_analytics_workspace_id = null
  5. diags_sa = null
  6. eh_id = ""
  7. eh_name = null
  8. }
  9. }

Output

Name Description
kube_config kube_config block that comprised crendetials
kube_config_raw Raw Kubernetes config to be used by kubectl and other compatible tools
ssh_key The private key used by worker nodes

NOTE: kube_config credentials can be used with the Kubernetes Provider like so:

  1. provider "kubernetes" {
  2. host = "${azurerm_kubernetes_cluster.main.kube_config.0.host}"
  3. username = "${azurerm_kubernetes_cluster.main.kube_config.0.username}"
  4. password = "${azurerm_kubernetes_cluster.main.kube_config.0.password}"
  5. client_certificate = "${base64decode(azurerm_kubernetes_cluster.main.kube_config.0.client_certificate)}"
  6. client_key = "${base64decode(azurerm_kubernetes_cluster.main.kube_config.0.client_key)}"
  7. cluster_ca_certificate = "${base64decode(azurerm_kubernetes_cluster.main.kube_config.0.cluster_ca_certificate)}"
  8. }

Contribute

Pull requests are welcome to evolve this module and integrate new features.