无法在路由表后提供私有 AKS

问题描述 投票:0回答:0

我正在尝试使用现有子网配置私有 AKS:

resource "azurerm_kubernetes_cluster" "aks" {
  automatic_channel_upgrade = "patch"
  azure_policy_enabled      = true
  dns_prefix                = "dns-aks"
  location                  = var.rg_location
  name                      = "aks"
  private_cluster_enabled   = true
  resource_group_name       = var.rg_name
  node_resource_group       = var.aks_node_resource_group

  default_node_pool {
    enable_auto_scaling = true
    max_count           = 5
    min_count           = 2
    max_pods            = 24
    name           = "systempool"
    vm_size        = "Standard_B4ms"
    vnet_subnet_id = azurerm_subnet.snet.id
  }

  identity {
    type = "SystemAssigned"
  }

  network_profile {
    network_plugin    = "azure"
    load_balancer_sku = "standard"
    docker_bridge_cidr = "172.17.0.1/16"
    dns_service_ip     = "10.0.0.10"
    service_cidr       = "10.0.0.0/16"
  }
}

resource "azurerm_virtual_network" "vnet" {
  for_each            = local.vnet
  name                = each.value.name
  resource_group_name = var.rg_name
  location            = var.rg_location
  address_space       = each.value.address_space
  dns_servers         = each.value.dns_servers

  tags = each.value.tags
}

resource "azurerm_subnet" "snet" {
  for_each             = local.snet
  name                 = each.value.name
  resource_group_name  = var.rg_name
  address_prefixes     = each.value.address_prefix
  virtual_network_name = each.value.vnet_name
  service_endpoints    = each.value.service_endpoints
}

resource "azurerm_route_table" "rt" {
  name                = var.rt_name
  location            = var.rg_location
  resource_group_name = var.rg_name

  tags = var.rt_tags

  depends_on = [azurerm_kubernetes_cluster.aks]
}

resource "azurerm_route" "udr" {
  for_each               = local.udr
  name                   = each.key
  resource_group_name    = var.rg_name
  address_prefix         = each.value
  next_hop_in_ip_address = "172.25.3.11"
  next_hop_type          = "VirtualAppliance"
  route_table_name       = azurerm_route_table.rt.name
}

如果我将“depends_on”添加到路由表并使 Terraform 在路由表之前部署 AKS,这会很好用,但我认为使用“depends_on”不是一个好主意。

这是没有'depends_on'的错误:

│ Error: waiting for creation of Managed Cluster (Subscription: "xxxx-xxxx-xxxx-xxxx"
│ Resource Group Name: "rg-aks"
│ Resource Name: "rg-aks"): Code="CreateVMSSAgentPoolFailed" Message="Unable to establish outbound connection from agents, please see https://aka.ms/aks-required-ports-and-addresses for more information. Details: 
Code=\"VMExtensionProvisioningError\" Message=\"VM has reported a failure when processing extension 'vmssCSE'. Error message: \\\"Enable failed: failed to execute command: command terminated with exit status=50\\n[stdout]\\n{ \\\"ExitCode\\\": \\\"50\\\", \\\"Output\\\": \\\":01:34 --:--:-- 0\\\\r 0 0 0 0 0 0 0 0 --:--:-- 0:01:35 --:--:-- 0\\\\r 0 0 0 0 0 0 0 0 --:--:-- 0:01:36 --:--:-- 0\\\\r 0 0 0 0 0 0 0 0 --:--:-- 0:01:37 --:--:-- 0\\\\r 0 0 0 0 0 0 0 0 --:--:-- 0:01:38 --:--:-- 0\\\\r 0 0 0 0 0 0 0 0 --:--:-- 0:01:39 --:--:-- 0\\\\r 0 0 0 0 0 0 0 0 --:--:-- 0:01:40 --:--:-- 0\\\\r 0 0 0 0 0 0 0 0 --:--:-- 0:01:41 --:--:-- 0\\\\r 0 0 0 0 0 0 0 0 --:--:-- 0:01:42 --:--:-- 0\\\\r 0 0 0 0 0 0 0 0 --:--:-- 0:01:43 --:--:-- 0\\\\r 0 0 0 0 0 0 0 0 --:--:-- 0:01:44 --:--:-- 0\\\\r 0 0 0 0 0 0 0 0 --:--:-- 0:01:45 --:--:-- 0\\\\r 0 0 0 0 0 0 0 0 --:--:-- 0:01:46 --:--:-- 0\\\\r 0 0 0 0 0 0 0 0 --:--:-- 0:01:47 --:--:-- 0\\\\r 0 0 0 0 0 0 0 0 --:--:-- 0:01:48 --:--:-- 0\\\\r 0 0 0 0 0 0 0 0 --:--:-- 0:01:49 --:--:-- 0\\\\r 0 0 0 0 0 0 0 0 --:--:-- 0:01:50 --:--:-- 0\\\\r 0 0 0 0 0 0 0 0 --:--:-- 0:01:51 --:--:-- 0\\\\r 0 0 0 0 0 0 0 0 --:--:-- 0:01:52 --:--:-- 0\\\\r 0 0 0 0 0 0 0 0 --:--:-- 0:01:53 --:--:-- 0\\\\r 0 0 0 0 0 0 0 0 --:--:-- 0:01:54 --:--:-- 0\\\\r 0 0 0 0 0 0 0 0 --:--:-- 0:01:55 --:--:-- 0\\\\r 0 0 0 0 0 0 0 0 --:--:-- 0:01:56 --:--:-- 0\\\\r 0 0 0 0 0 0 0 0 --:--:-- 0:01:57 --:--:-- 0\\\\r 0 0 0 0 0 0 0 0 --:--:-- 0:01:58 --:--:-- 0\\\\r 0 0 0 0 0 0 0 0 --:--:-- 0:01:59 --:--:-- 0\\\\r 0 0 0 0 0 0 0 0 --:--:-- 0:02:00 --:--:-- 0\\\\r 0 0 0 0 0 0 0 0 --:--:-- 0:02:01 --:--:-- 0\\\\r 0 0 0 0 0 0 0 0 --:--:-- 0:02:02 --:--:-- 0\\\\r 0 0 0 0 0 0 0 0 --:--:-- 0:02:03 --:--:-- 0\\\\r 0 0 0 0 0 0 0 0 --:--:-- 0:02:04 --:--:-- 0\\\\r 0 0 0 0 0 0 0 0 --:--:-- 0:02:05 --:--:-- 0\\\\r 0 0 0 0 0 0 0 0 --:--:-- 0:02:06 --:--:-- 0\\\\r 0 0 0 0 0 0 0 0 --:--:-- 0:02:07 --:--:-- 0\\\\r 0 0 0 0 0 0 0 0 --:--:-- 0:02:08 --:--:-- 0* 
connect to 204.79.197.219 port 443 failed: Connection timed out\\\\n* Failed to connect to mcr.microsoft.com port 443: Connection timed out\\\\n* Closing connection 0\\\\ncurl: (7) Failed to connect to mcr.microsoft.com port 443: Connection timed out\\\\n\\\\nreal\\\\t2m9.208s\\\\nuser\\\\t0m0.023s\\\\nsys\\\\t0m0.026s\\\\n+ exit 50\\\", \\\"Error\\\": \\\"\\\", \\\"ExecDuration\\\": \\\"429\\\", \\\"KernelStartTime\\\": \\\"Tue 2023-02-14 13:46:44 UTC\\\", \\\"CloudInitLocalStartTime\\\": \\\"Tue 2023-02-14 13:46:51 UTC\\\", \\\"CloudInitStartTime\\\": \\\"Tue 2023-02-14 13:46:55 UTC\\\", \\\"CloudFinalStartTime\\\": \\\"Tue 2023-02-14 13:47:03 UTC\\\", \\\"NetworkdStartTime\\\": \\\"Tue 2023-02-14 13:46:53 UTC\\\", \\\"CSEStartTime\\\": \\\"Tue Feb 14 13:47:09 UTC 2023\\\", \\\"GuestAgentStartTime\\\": \\\"Tue 2023-02-14 13:47:01 UTC\\\", \\\"SystemdSummary\\\": \\\"Startup finished in 404ms (firmware) + 1.769s (loader) + 6.208s (kernel) + 5min 13.339s (userspace) = 5min 21.722s\\\\ngraphical.target reached after 12.507s in userspace\\\", \\\"BootDatapoints\\\": { \\\"KernelStartTime\\\": \\\"Tue 2023-02-14 13:46:44 UTC\\\", \\\"CSEStartTime\\\": \\\"Tue Feb 14 13:47:09 UTC 2023\\\", \\\"GuestAgentStartTime\\\": \\\"Tue 2023-02-14 13:47:01 UTC\\\", \\\"KubeletStartTime\\\": \\\"\\\" } }\\n\\n[stderr]\\n\\\"\\r\\n\\r\\nMore information on troubleshooting is available at https://aka.ms/VMExtensionCSELinuxTroubleshoot \" Target=\"0\""

预期结果: 没有路由表 'depends_on' AKS

就可以成功创建 AKS
azure azure-devops terraform azure-aks terraform-provider-azure
© www.soinside.com 2019 - 2024. All rights reserved.