azure - 使用 Terraform 将 AKS 群集附加到现有 VNET

标签 azure kubernetes terraform azure-aks

我是 DevOps 和 Terraform 领域的新手,我想问以下问题。我已经在资源组“网络”中创建了一个名为“myVNET”的 VNET(使用门户)。我正在尝试使用 Terraform 实现 AKS 集群。我的 main.tf 文件如下

provider "azurerm" {
  subscription_id = var.subscription_id
  client_id       = var.client_id
  client_secret   = var.client_secret
  tenant_id       = var.tenant_id
features {}
}
resource "azurerm_resource_group" "MyPlatform" {
  name     = var.resourcename
  location = var.location
}
resource "azurerm_kubernetes_cluster" "aks-cluster" {
  name                = var.clustername
  location            = azurerm_resource_group.MyPlatform.location
  resource_group_name = azurerm_resource_group.MyPlatform.name
  dns_prefix          = var.dnspreffix
default_node_pool {
    name       = "default"
    node_count = var.agentnode
    vm_size    = var.size
  }
service_principal {
    client_id     = var.client_id
    client_secret = var.client_secret
  }

network_profile {
    network_plugin     = "azure"
    load_balancer_sku  = "standard"
    network_policy     = "calico"
  }
}

我的问题如下:如何将集群附加到 VNET?

最佳答案

您可以通过将子网 ID 分配给节点池 vnet_subnet_id 来实现此目的.

data "azurerm_subnet" "subnet" {
  name                 = "<name of the subnet to run in>"
  virtual_network_name = "MyVNET"
  resource_group_name  = "Networks"
}
...
resource "azurerm_kubernetes_cluster" "aks-cluster" {
...
    default_node_pool {
      name             = "default"
      ...
      vnet_subnet_id   = data.azurerm_subnet.subnet.id
    }
...

可以引用这个existing module如果不直接使用它,则构建自己的模块。

关于azure - 使用 Terraform 将 AKS 群集附加到现有 VNET,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70311005/

相关文章:

Kubernetes:仅将 Fluentd 安装到命名空间

terraform - 为什么我需要 "update"路径上的 "auth/token/create"功能来读取 AWS secret 引擎生成的 secret ?

python - 使用 azure 函数时未找到名为 twilio 的模块

asp.net-mvc - 尝试将 Azure 媒体播放器集成到 React JS 中。但 Azure 依赖的 JavaScript lib 函数未找到 "amp"

c# - Azure 移动服务错误 : more than one static class with name was found as bootstrapper in assemblies

azure - 在 Azure AKS 中运行 Docker Windows 容器时获取 'didn' t 匹配节点选择器

docker - 使用Kubernetes的OpenStack服务的容器化?

amazon-web-services - 使用 Terraform 在对象内迭代列表

azure - 如何获取 Terraform 内标记的 Azure VNet 的事件地址空间?

Microsoft Azure 网站上的 PHP Websockets 扩展