【问题标题】:Azure AKS Terraform - how to specify VM SizeAzure AKS Terraform - 如何指定 VM 大小
【发布时间】:2020-01-25 18:12:13
【问题描述】:

在我的 Azure 订阅中,我尝试使用 Terraform 创建一个 AKS 集群。 我的 main.tf 看起来像这样:

## Azure resource provider ##
provider "azurerm" {
  version = "=1.36.1"
}

## Azure resource group for the kubernetes cluster ##
resource "azurerm_resource_group" "aks_demo" {
  name     = var.resource_group_name
  location = var.location
}

## AKS kubernetes cluster ##
resource "azurerm_kubernetes_cluster" "aks_demo" { 
  name                = var.cluster_name
  resource_group_name = azurerm_resource_group.aks_demo.name
  location            = azurerm_resource_group.aks_demo.location
  dns_prefix          = var.dns_prefix

  linux_profile {
    admin_username = var.admin_username

    ## SSH key is generated using "tls_private_key" resource
    ssh_key {
      key_data = "${trimspace(tls_private_key.key.public_key_openssh)} ${var.admin_username}@azure.com"
    }
  }

  agent_pool_profile {
    name        = "default"
    count           = var.agent_count
    vm_size         = "Standard_D2"
    os_type         = "Linux"
    os_disk_size_gb = 30
  }

  service_principal {
    client_id     = var.client_id
    client_secret = var.client_secret
  }

  tags = {
    Environment = "Production"
  }
}

## Private key for the kubernetes cluster ##
resource "tls_private_key" "key" {
  algorithm   = "RSA"
}

## Save the private key in the local workspace ##
resource "null_resource" "save-key" {
  triggers = {
    key = tls_private_key.key.private_key_pem
  }

  provisioner "local-exec" {
    command = <<EOF
      mkdir -p ${path.module}/.ssh
      echo "${tls_private_key.key.private_key_pem}" > ${path.module}/.ssh/id_rsa
      chmod 0600 ${path.module}/.ssh/id_rsa
EOF
  }
}

## Outputs ##

# Example attributes available for output
output "id" {
    value = "${azurerm_kubernetes_cluster.aks_demo.id}"
}

output "client_key" {
  value = "${azurerm_kubernetes_cluster.aks_demo.kube_config.0.client_key}"
}

output "client_certificate" {
  value = "${azurerm_kubernetes_cluster.aks_demo.kube_config.0.client_certificate}"
}

output "cluster_ca_certificate" {
  value = "${azurerm_kubernetes_cluster.aks_demo.kube_config.0.cluster_ca_certificate}"
}

output "kube_config" {
  value = azurerm_kubernetes_cluster.aks_demo.kube_config_raw
}

output "host" {
  value = azurerm_kubernetes_cluster.aks_demo.kube_config.0.host
}

output "configure" {
  value = <<CONFIGURE
Run the following commands to configure kubernetes client:
$ terraform output kube_config > ~/.kube/aksconfig
$ export KUBECONFIG=~/.kube/aksconfig
Test configuration using kubectl
$ kubectl get nodes
CONFIGURE
}

我的 variables.tf 看起来像这样:

## Azure config variables ##
variable "client_id" {}

variable "client_secret" {}

variable location {
  default = "Central US"
}

## Resource group variables ##
variable resource_group_name {
  default = "aksdemo-rg"
}


## AKS kubernetes cluster variables ##
variable cluster_name {
  default = "aksdemo1"
}

  variable "vm_size" {
  default = "Standard_A0"
  }

variable "agent_count" {
  default = 3
}

variable "dns_prefix" {
  default = "aksdemo"
}

variable "admin_username" {
    default = "demo"
}

当我运行 terraform apply 时,我收到此错误:

    Error: Error creating Managed Kubernetes Cluster "aksdemo1" (Resource Group "aksdemo-rg"): 

containerservice.ManagedClustersClient#CreateOrUpdate: Failure sending request: StatusCode=400 -- 

Original Error: Code="BadRequest" 

Message="The VM size of AgentPoolProfile:default is not allowed in your subscription in location 'centralus'. The available VM sizes are Standard_A2,Standard_A2_v2,Standard_A2m_v2,Standard_A3,Standard_A4,Standard_A4_v2,Standard_A4m_v2,

Standard_A5,Standard_A6,Standard_A7,Standard_A8_v2,Standard_A8m_v2,Standard_B12ms,Standard_B16ms,Standard_B20ms,Standard_B2ms,Standard_B2s,Standard_B4ms,Standard_B8ms,Standard_D11_v2,Standard_D12_v2,

Standard_D13_v2,Standard_D14_v2,Standard_D15_v2,Standard_D16_v3,Standard_D16s_v3,Standard_D1_v2,Standard_D2_v2,Standard_D2_v3,Standard_D2s_v3,Standard_D32_v3,Standard_D32s_v3,Standard_D3_v2,Standard_D48_v3,

Standard_D48s_v3,Standard_D4_v2,Standard_D4_v3,Standard_D4s_v3,Standard_D5_v2,Standard_D64_v3,Standard_D64s_v3,Standard_D8_v3,Standard_D8s_v3,Standard_DS1,Standard_DS11,Standard_DS11_v2,Standard_DS12,Standard_DS12_v2,Standard_DS13,Standard_DS13-2_v2,Standard_DS13-4_v2,Standard_DS13_v2,Standard_DS14,Standard_DS14-4_v2,Standard_DS14-8_v2,Standard_DS14_v2,Standard_DS15_v2,Standard_DS1_v2,Standard_DS2,Standard_DS2_v2,Standard_DS3,Standard_DS3_v2,Standard_DS4,Standard_DS4_v2,Standard_DS5_v2,Standard_E16_v3,Standard_E16s_v3,Standard_E2_v3,Standard_E2s_v3,Standard_E32-16s_v3,Standard_E32-8s_v3,Standard_E32_v3,Standard_E32s_v3,Standard_E48_v3,Standard_E48s_v3,Standard_E4_v3,Standard_E4s_v3,Standard_E64-16s_v3,Standard_E64-32s_v3,Standard_E64_v3,Standard_E64i_v3,Standard_E64is_v3,Standard_E64s_v3,Standard_E8_v3,Standard_E8s_v3,Standard_F16,Standard_F16s,Standard_F16s_v2,Standard_F2,Standard_F2s,Standard_F2s_v2,Standard_F32s_v2,Standard_F4,Standard_F48s_v2,Standard_F4s,Standard_F4s_v2,Standard_F64s_v2,Standard_F72s_v2,Standard_F8,

Standard_F8s,Standard_F8s_v2 

For more details, please visit https://aka.ms/cpu-quota"

这让我很困惑,因为显然有一个名为 vm_size 的变量

我可以更改哪些内容才能使其正常工作?

【问题讨论】:

    标签: terraform azure-aks terraform-provider-azure


    【解决方案1】:

    正如我从您提供的代码和遇到的错误中看到的那样,您在代码中犯了错误。

    你做了什么代码:

    agent_pool_profile {
        name        = "default"
        count           = var.agent_count
        vm_size         = "Standard_D2"
        os_type         = "Linux"
        os_disk_size_gb = 30
      }
    

    当你使用虚拟机大小的变量时应该是这样的:

      agent_pool_profile {
        name        = "default"
        count           = var.agent_count
        vm_size         = var.vm_size
        os_type         = "Linux"
        os_disk_size_gb = 30
      }
    

    VM 大小应该适合您自己和需求。例如,就像它在Terraform example 中显示的那样。

    【讨论】:

      【解决方案2】:

      错误消息告诉您,您正在尝试使用 VM 大小或 VM 类型(如果您愿意),在该位置您的订阅不可用,它还为您提供了您可以选择的所有 VM 大小。

      请注意,您可能已经复制粘贴了这个:

      agent_pool_profile {
          name        = "default"
          count           = var.agent_count
          vm_size         = "Standard_D2"
          os_type         = "Linux"
          os_disk_size_gb = 30
        }
      

      VM 大小在那里被硬编码,因此您默认的 Standard_A0value 不会被拾取。 在这里调试的方法不止一种,首先我要确保使用了正确的值,然后更改 VM 类型以查看是否可行。

      【讨论】:

        猜你喜欢
        • 2022-11-22
        • 1970-01-01
        • 1970-01-01
        • 2017-11-03
        • 1970-01-01
        • 2020-12-04
        • 2018-10-30
        • 2021-05-01
        • 2020-01-05
        相关资源
        最近更新 更多