Terraform 在 AKS 节点资源组中创建入口应用程序网关

Terraform Create Ingress Application Gateway in AKS Node Resource Group

AKS节点资源组在创建AKS集群之前不能已经存在,所以在同一个节点资源组中创建应用网关意味着需要在AKS集群之后创建应用网关。但是在AKS集群中指定了ingress application gateway add-on,造成了循环依赖:

resource "azurerm_kubernetes_cluster" "example" {
    ...
    ingress_application_gateway {
      enabled    = true
      gateway_id = azurerm_application_gateway.example.id
    }
}

resource "azurerm_application_gateway" "example" {
    ...
    resource_group_name = azurerm_kubernetes_cluster.example.node_resource_group
}

有人可以告诉我如何在 AKS 节点资源组中创建入口应用程序网关吗?非常感谢

无法在 AKS 节点资源组中部署 App Gateway,因为您需要在 AKS 之前创建 App Gateway,并且 AKS 节点资源组不能是现有资源组.

我在我的环境中使用 可选参数AKS 资源块 允许您为 node_resource_group.

命名

我创建了一个资源组并在那里部署了应用程序网关然后在中提到AKS 资源块 使用 节点相同的 rg资源组,内容如下:

data "azurerm_resource_group" "example" { #existing resource group where the AKS is being deployed
  name="ansumantest"
}
resource "azurerm_resource_group" "noderg" {#new resource group where app gateway will be deployed and used as node resource group for AKS
  name     = "AKS_MG-ansumanaks-eastus"
  location = "East US"
}
resource "azurerm_application_gateway" "network" {
  name                = "ansuman-appgw"
  resource_group_name = azurerm_resource_group.noderg.name
  location            = azurerm_resource_group.noderg.location
.....
}
resource "azurerm_kubernetes_cluster" "example" {
  name                = "ansuman-aks1"
  location            = data.azurerm_resource_group.example.location
  resource_group_name = data.azurerm_resource_group.example.name
  dns_prefix          = "ansumanaks1"
  node_resource_group = azurerm_application_gateway.network.resource_group_name ##uses the appgw rg as Node rsource group

addon_profile {
  ingress_application_gateway {
    enabled    = true
    gateway_id = azurerm_application_gateway.network.id
  }
}
....
}

输出:

因此,您可以在同一资源组[=49=中创建应用程序网关 ] 其中 网络组件 AKS 正在创建中。