繁体   English   中英

使用 Terraform 创建具有托管标识的 Azure AKS 会出现 AutoUpgradePreview not enabled 错误

[英]Create Azure AKS with Managed Identity using Terraform gives AutoUpgradePreview not enabled error

我正在尝试使用 Terraform 创建一个具有托管身份的 AKS 集群。这是我到目前为止的代码,非常基本和标准,来自我在网上找到的一些文档和博客文章。

terraform {
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "2.79.1"
    }
  }
}

provider "azurerm" {
  features {}

  use_msi = true
}

resource "azurerm_resource_group" "rg" {
  name     = "prod_test"
  location = "northeurope"
}

resource "azurerm_kubernetes_cluster" "cluster" {
  name                = "prod_test_cluster"
  location            = azurerm_resource_group.rg.location
  resource_group_name = azurerm_resource_group.rg.name
  dns_prefix          = "weak"

  default_node_pool {
    name       = "default"
    node_count = "4"
    vm_size    = "standard_ds3_v2"
  }

  identity {
    type = "SystemAssigned"
  }
}

这是我无法解决的错误消息。 有什么想法吗?

Error: creating Managed Kubernetes Cluster "prod_test_cluster" (Resource Group "prod_test"): containerservice.ManagedClustersClient#CreateOrUpdate: Failure sending request: StatusCode=0 -- Original Error: Code="BadRequest" Message="Feature Microsoft.ContainerService/AutoUpgradePreview is not enabled. Please see https://aka.ms/aks/previews for how to enable features."
│ 
│   with azurerm_kubernetes_cluster.cluster,
│   on main.tf line 19, in resource "azurerm_kubernetes_cluster" "cluster":
│   19: resource "azurerm_kubernetes_cluster" "cluster" {
│ 

我在我的环境中对其进行了测试,并遇到了与您在下面看到的相同的问题:

在此处输入图像描述

  • 因此,为了描述AutoChannelUpgrade于 2021 年 8 月进入公共预览版的问题。根据terraform azurerm provider 2.79.0 ,默认情况下它会在后端将该值传递给 none 但因为我们尚未注册该功能无法给出错误Feature Microsoft.ContainerService/AutoUpgradePreview is not enabled

  • 要确认您没有注册该功能,您可以使用以下命令:

     az feature show -n AutoUpgradePreview --namespace Microsoft.ContainerService

    您会看到它未注册,如下所示:

    在此处输入图像描述


现在要克服这个问题,您可以尝试下面给出的两种解决方案:

  1. 您可以尝试使用terraform azurerm provider 2.78.0而不是2.79.1

  2. 其他解决方案是注册该功能,然后您可以使用您正在使用的相同代码。

    您可以按照以下步骤操作:

  • 您可以使用以下命令注册该功能(注册大约需要 5 分钟):

     az login --identity az feature register --namespace Microsoft.ContainerService -n AutoUpgradePreview
  • 完成上述操作后,您可以使用以下命令检查注册状态:

     az feature registration show --provider-namespace Microsoft.ContainerService -n AutoUpgradePreview

    在此处输入图像描述

  • 功能状态注册后,您可以通过 terraform 申请您的代码。

    我在我的 VM 上使用以下代码对其进行了测试:

     provider "azurerm" { features {} subscription_id = "948d4068-xxxxx-xxxxxx-xxxx-e00a844e059b" tenant_id = "72f988bf-xxxxx-xxxxxx-xxxxx-2d7cd011db47" use_msi = true } resource "azurerm_resource_group" "rg" { name = "terraformtestansuman" location = "west us 2" } resource "azurerm_kube.netes_cluster" "cluster" { name = "prod_test_cluster" location = azurerm_resource_group.rg.location resource_group_name = azurerm_resource_group.rg.name dns_prefix = "weak" default_node_pool { name = "default" node_count = "4" vm_size = "standard_ds3_v2" } identity { type = "SystemAssigned" } }

    输出: 在此处输入图像描述

    在此处输入图像描述

参考:

Github 问题

如果未使用 Microsoft Installer 在 VM 上安装,请安装 Azure CLI

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM