【问题标题】:Destroying Rancher2_Cluster with terraform is failing due to aks resources in "deleting" state由于 aks 资源处于“删除”状态,使用 terraform 销毁 Rancher2_Cluster 失败
【发布时间】:2021-08-18 17:30:03
【问题描述】:

我们在 terraform 与 Rancher2 和 AKS 的组合中遇到了问题。我们正在使用 terraform 部署具有 aks 配置的 rancher2_cluster,同时创建一个新子网。

在尝试销毁所有内容时,我们遇到了一个问题,即 azurerm_subnet 仍被 azure 中的集群节点使用。因此无法删除。

Message="Subnet subnet_name is in use by /subscriptions/xxx-xx-xx-xx-xxx/resourceGroups/MC_cluster-resource-group-name_location/providers/Microsoft.Network/networkInterfaces/aks-node-id-nic-0/ipConfigurations/ipconfig1 and cannot be deleted. In order to delete the subnet, delete all the resources within the subnet. See aka.ms/deletesubnet." Details=[]

如果我们运行 terraform destroy,在我们检查与 aks 集群相关的所有内容都在 azure 端销毁后,子网将被删除。

我们尝试使用 rancher2_sync。但到目前为止还没有效果。有没有其他方法可以实现平滑删除我们使用过的每一个资源?

作为最后的手段,我看到了在销毁之前实现睡眠的方式,在我看来这不是很好

# This resource will destroy (at least) 30 seconds after null_resource.next
resource "null_resource" "previous" {}

resource "time_sleep" "wait_30_seconds" {
  depends_on = [null_resource.previous]

  destroy_duration = "30s"
}

# This resource will create (potentially immediately) after null_resource.previous
resource "null_resource" "next" {
  depends_on = [time_sleep.wait_30_seconds]
}

【问题讨论】:

  • 对于观看此内容的任何人,解决方法都适用于卧铺 [设置为 5 分钟]。但是,使用 azurerm_kubernetes_cluster 资源时会更加顺畅。无论如何,与使用 rancher2_cluster 资源相比,这使您可以更好地控制集群本身。 Tbh,我现在已经试用了新的 v2 资源。

标签: terraform azure-aks terraform-provider-azure rancher azure-application-gateway


【解决方案1】:

@maes,

请您查看以下内容:

  1. 验证删除顺序,确认在 vnet 删除之前从未运行过 AKS 删除。
  2. 如果 (1) 为真,请按照https://www.terraform.io/docs/cli/commands/graph.html 导出并查看依赖关系图。您应该找到从 AKS 到 vnet 的依赖关系。
  3. 如果没有,请在 https://learn.hashicorp.com/tutorials/terraform/dependencies#manage-explicit-dependencies 之后尝试depends_on。

【讨论】:

  • 嗨,Srijit,谢谢您的回复。与此同时,我尝试了另一条路线,效果更好。我猜这是 rancher2_provider 的问题,它不会等到集群被破坏。我们现在已将集群创建移至 azurerm_kubernetes_cluster 提供程序,当我们执行销毁时,它会识别依赖项并按预期删除所有内容。
猜你喜欢
  • 1970-01-01
  • 2019-11-14
  • 2022-07-13
  • 1970-01-01
  • 2020-11-17
  • 2021-04-05
  • 1970-01-01
  • 1970-01-01
  • 2020-08-01
相关资源
最近更新 更多