【问题标题】:Terraform Plan deleting AKS Node PoolTerraform 计划删除 AKS 节点池
【发布时间】:2022-01-24 14:52:29
【问题描述】:

如果我们在节点池中增加工作节点,Terraform 计划总是强制重新创建 AKS 集群

尝试通过 Terraform 创建具有 1 个工作节点的 AKS 集群,进展顺利,集群已启动并正在运行。

发布后,我尝试在我的 AKS 中再添加一个工作节点,Terraform Show Plan:2 添加,0 更改,2 销毁。

不确定我们如何在 aks 节点池中增加工作节点,如果它延迟了现有的节点池。

  default_node_pool {
    name                  = var.nodepool_name
    vm_size               = var.instance_type
    orchestrator_version  = data.azurerm_kubernetes_service_versions.current.latest_version
    availability_zones    = var.zones
    enable_auto_scaling   = var.node_autoscalling
    node_count            = var.instance_count
    enable_node_public_ip = var.publicip
    vnet_subnet_id        = data.azurerm_subnet.subnet.id
    node_labels = {
      "node_pool_type"         = var.tags[0].node_pool_type
      "environment"            = var.tags[0].environment
      "nodepool_os"            = var.tags[0].nodepool_os
      "application"            = var.tags[0].application
      "manged_by"              = var.tags[0].manged_by
 }
}

错误

Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
-/+ destroy and then create replacement

Terraform will perform the following actions:

  # azurerm_kubernetes_cluster.aks_cluster must be replaced
-/+ resource "azurerm_kubernetes_cluster" "aks_cluster" {

谢谢 萨蒂扬

【问题讨论】:

    标签: kubernetes terraform azure-aks terraform-provider-azure


    【解决方案1】:

    我通过创建一个具有 2 个节点计数的集群在我的环境中进行了相同的测试,然后使用如下所示将其更改为 3:

    如果您使用的是HTTP_proxy,那么它将默认强制替换该块,这就是整个集群将被新配置替换的原因。

    因此,对于解决方案,您可以在代码中使用生命周期块,如下所示:

      lifecycle {
        ignore_changes = [http_proxy_config]
      }
    

    代码将是:

    resource "azurerm_kubernetes_cluster" "aks_cluster" {
      name                       = "${var.global-prefix}-${var.cluster-id}-${var.envid}-azwe-aks-01"
      location                   = data.azurerm_resource_group.example.location
      resource_group_name        = data.azurerm_resource_group.example.name
      dns_prefix                 = "${var.global-prefix}-${var.cluster-id}-${var.envid}-azwe-aks-01"
      kubernetes_version         = var.cluster-version
      private_cluster_enabled    = var.private_cluster
    
    
    
      default_node_pool {
        name                  = var.nodepool_name
        vm_size               = var.instance_type
        orchestrator_version  = data.azurerm_kubernetes_service_versions.current.latest_version
        availability_zones    = var.zones
        enable_auto_scaling   = var.node_autoscalling
        node_count            = var.instance_count
        enable_node_public_ip = var.publicip
        vnet_subnet_id        = azurerm_subnet.example.id  
      }
    
    
    # RBAC and Azure AD Integration Block
      role_based_access_control {
        enabled = true
    } 
    
      http_proxy_config {
        http_proxy       = "http://xxxx"
        https_proxy      = "http://xxxx"
        no_proxy         = ["localhost","xxx","xxxx"]
      }
    # Identity (System Assigned or Service Principal)
      identity {
        type = "SystemAssigned"
    }
    
    # Add On Profiles
      addon_profile {
        azure_policy {enabled =  true}
      }
    # Network Profile
      network_profile {
        network_plugin = "azure"
        network_policy = "calico"
      }
      lifecycle {
        ignore_changes = [http_proxy_config]
      }
    }
    

    【讨论】:

    • 它解决了这个问题,但现在整个被代理了,我的意思是集群上的所有 pod 都在继承代理,这是有风险的。
    猜你喜欢
    • 1970-01-01
    • 2021-12-17
    • 1970-01-01
    • 2022-11-21
    • 2017-02-16
    • 2020-02-06
    • 2021-08-21
    • 2021-08-03
    • 2019-09-12
    相关资源
    最近更新 更多