我是 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/