Azure AKS Terraform-如何指定虚拟机大小

Azure AKS Terraform-如何指定虚拟机大小,terraform,azure-aks,terraform-provider-azure,Terraform,Azure Aks,Terraform Provider Azure,在我的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.reso

在我的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
}
## 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的变量


要使其工作,我可以更改哪些内容?

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

请注意,您可能复制粘贴了以下内容:

agent_pool_profile {
    name        = "default"
    count           = var.agent_count
    vm_size         = "Standard_D2"
    os_type         = "Linux"
    os_disk_size_gb = 30
  }
虚拟机大小在那里是硬编码的,因此默认的
Standard_A0
值未被提取。
这里的调试方法不止一种,首先我要确保使用了正确的值,然后更改VM类型以查看其是否有效。

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

请注意,您可能复制粘贴了以下内容:

agent_pool_profile {
    name        = "default"
    count           = var.agent_count
    vm_size         = "Standard_D2"
    os_type         = "Linux"
    os_disk_size_gb = 30
  }
虚拟机大小在那里是硬编码的,因此默认的
Standard_A0
值未被提取。
在这里调试的方法不止一种,首先我要确保使用了正确的值,然后更改VM类型以查看是否有效。

从您提供的代码和收到的错误中可以看出,您在代码中犯了错误

您编写的代码:

agent_pool_profile {
    name        = "default"
    count           = var.agent_count
    vm_size         = "Standard_D2"
    os_type         = "Linux"
    os_disk_size_gb = 30
  }
当您将变量用于VM大小时,应该是这样的:

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

虚拟机的大小应该适合您自己和需求。例如,正如在.

中所示,从您提供的代码和得到的错误中我看到,您在代码中犯了错误

您编写的代码:

agent_pool_profile {
    name        = "default"
    count           = var.agent_count
    vm_size         = "Standard_D2"
    os_type         = "Linux"
    os_disk_size_gb = 30
  }
当您将变量用于VM大小时,应该是这样的:

  agent_pool_profile {
    name        = "default"
    count           = var.agent_count
    vm_size         = var.vm_size
    os_type         = "Linux"
    os_disk_size_gb = 30
  }
虚拟机的大小应该适合您自己和需求。例如,正如图中所示