温馨提示:本文翻译自stackoverflow.com,查看原文请点击:azure - How to assign only one static public IP to AKS-multiAZ Loadbalancer
azure azure-aks azure-load-balancer terraform

azure - 如何仅将一个静态公共IP分配给AKS-multiAZ Loadbalancer

发布于 2020-03-31 23:41:40

我正在设置一个多可用区AKS集群,我想为该负载均衡器分配一个静态的公共IP。这是我所拥有的:

#### Creating a Public static IP ####
resource "azurerm_public_ip" "lb-public-ip1" {
  name                = "${var.public_ip_name}"
  location            = "${var.location}"
  resource_group_name = "${var.resource_group_name}"
  allocation_method   = "Static"
  ip_version          = "IPv4"
  sku                 = "standard"
  #domain_name_label   =
  tags = {
    Environment = "${var.environment}"
    owner       = "${var.resource_owner}"
    created-by  = "${var.policy_created_by}"
  }
  depends_on    = ["null_resource.module_depends_on"]
}
data "azurerm_public_ip" "lb-public-ip1" {
  name                = "${azurerm_public_ip.lb-public-ip1.name}"
  resource_group_name = "${azurerm_public_ip.lb-public-ip1.resource_group_name}"
  depends_on          = ["null_resource.module_depends_on"]
}
resource "null_resource" "module_depends_on" {
  triggers = {
    value = "${length(var.module_depends_on)}"
  }
}

#### Creating AKS Cluster ####
resource "azurerm_kubernetes_cluster" "k8s" {
    name                = "${var.cluster_name}"
    location            = "${var.location}"
    resource_group_name = "${var.resource_group_name}"
    dns_prefix          = "${var.dns_prefix}"
    kubernetes_version  = "1.14.8"
    linux_profile {
        admin_username = "ubuntu"

        ssh_key {
            key_data = "${var.key_data}"
        }
    }

    default_node_pool {
        availability_zones    = ["1","2"]
        enable_auto_scaling   = true 
        enable_node_public_ip = false 
        max_count             = "8" 
        min_count             = "2" 
        name                  = "default" 
        node_count            = "${var.node_count}"  
        os_disk_size_gb       = "${var.os_disk_size}" 
        type                  = "VirtualMachineScaleSets" 
        vm_size               = "Standard_DS2_v2"
       }

    role_based_access_control {
          enabled = true
    }
    service_principal {
        client_id      = "${var.client_id}"
        client_secret  = "${var.client_secret}"
    }
    addon_profile {
        kube_dashboard {
              enabled = true
        }
        oms_agent {
        enabled                    = "${var.oms_agent_activation}"
        log_analytics_workspace_id = "${var.log_analytics_workspace_id}"
        }
    }
    network_profile {
        network_plugin    = "kubenet"
        load_balancer_sku = "Standard"
        load_balancer_profile {
            outbound_ip_address_ids = [ "${azurerm_public_ip.lb-public-ip1.id}" ]

        }
    }
    tags = {
        Environment = "${var.environment}"
        Name        = "${var.cluster_name}"
        owner       = "${var.resource_owner}"
        created-by  = "${var.policy_created_by}"
    }
    depends_on       = [azurerm_public_ip.lb-public-ip1]
}

通过此设置,它创建了一个称为kubernetes的AKS集群和LoadBalancer,并将我创建的静态公共IP分配给了LoadBalancer,而没有分配任何LB规则,我可以在“前端IP配置”下看到它还创建了另一个IP和所有LoadBalancer规则和HealthProbes分配给自动创建的IP。除此之外,还创建了两个后端池:kubernetes(2个虚拟机)和aksOutboundBackendPool(2个虚拟机)

在Azure文档中,它说:“默认情况下,如果未指定公共IP,公共IP前缀或IP数量,则会在与AKS群集相同的资源组中自动创建一个公共IP。” 但就我而言,我已经指定了PublicIP!

我想知道为什么它自己创建了另一个IP?如何跳过自动创建的IP,而仅使用已创建并分配给负载均衡器配置文件的IP,AKS如何将LoadBalancer规则和运行状况探测器分配给我分配的IP?

拥有多个公共IP的需求是什么?

最后,我将使用分配给PublicIP的istio入口网关。这就是为什么我只需要一个特定的公共IP。

另外我应该使用哪个后端池?

我只需要一个Prod Env具有高可用性的AKS集群,以防万一某个区域中的集群出现故障,则启动第二个区域中的集群。

任何帮助,将不胜感激。

查看更多

提问者
Matrix
被浏览
92
Charles Xu 2020-02-03 19:54

据我所知,当您创建AKS并创建静态公共IP以通过Terraform分配给其出站时,您只需要创建一个公共IP和AKS集群,而无需使用data源和null_resource因此,您的代码可以更改为:

#### Creating a Public static IP ####
resource "azurerm_public_ip" "lb-public-ip1" {
  name                = "${var.public_ip_name}"
  location            = "${var.location}"
  resource_group_name = "${var.resource_group_name}"
  allocation_method   = "Static"
  ip_version          = "IPv4"
  sku                 = "standard"
  #domain_name_label   =
  tags = {
    Environment = "${var.environment}"
    owner       = "${var.resource_owner}"
    created-by  = "${var.policy_created_by}"
  }
}


#### Creating AKS Cluster ####
resource "azurerm_kubernetes_cluster" "k8s" {
    name                = "${var.cluster_name}"
    location            = "${var.location}"
    resource_group_name = "${var.resource_group_name}"
    dns_prefix          = "${var.dns_prefix}"
    kubernetes_version  = "1.14.8"
    linux_profile {
        admin_username = "ubuntu"

        ssh_key {
            key_data = "${var.key_data}"
        }
    }

    default_node_pool {
        availability_zones    = ["1","2"]
        enable_auto_scaling   = true 
        enable_node_public_ip = false 
        max_count             = "8" 
        min_count             = "2" 
        name                  = "default" 
        node_count            = "${var.node_count}"  
        os_disk_size_gb       = "${var.os_disk_size}" 
        type                  = "VirtualMachineScaleSets" 
        vm_size               = "Standard_DS2_v2"
       }

    role_based_access_control {
          enabled = true
    }
    service_principal {
        client_id      = "${var.client_id}"
        client_secret  = "${var.client_secret}"
    }
    addon_profile {
        kube_dashboard {
              enabled = true
        }
        oms_agent {
        enabled                    = "${var.oms_agent_activation}"
        log_analytics_workspace_id = "${var.log_analytics_workspace_id}"
        }
    }
    network_profile {
        network_plugin    = "kubenet"
        load_balancer_sku = "Standard"
        load_balancer_profile {
            outbound_ip_address_ids = [ "${azurerm_public_ip.lb-public-ip1.id}" ]

        }
    }
    tags = {
        Environment = "${var.environment}"
        Name        = "${var.cluster_name}"
        owner       = "${var.resource_owner}"
        created-by  = "${var.policy_created_by}"
    }
    depends_on       = [azurerm_public_ip.lb-public-ip1]
}

并且会有两个后端池:aksOutboundBackendPool和kubernetes,以及一个出站规则:aksOutboundRule。没有磅规则和探针。一定是其他原因造成的。

最新帖子

最新文章