Terraform:如何在 AKS 群集的第二个负载均衡器中配置后端池 VM 规模集
Terraform: How can I configure the backend pool VM Scale Set in a second load balancer in an AKS Cluster
我已经通过 Terraform 配置了一个 AKS 集群。它作为标准部署了一个外部负载均衡器,该负载均衡器配置了一个指向默认池的 VM 规模集的后端池。
我现在想配置第二个(内部)负载均衡器,其后端池指向同一个 VM 规模集。这可能吗?如果是这样,我如何获得对该规模集的引用?以及如何将负载均衡器附加到规模集?
负载均衡器的配置:
resource "azurerm_lb" "aks-internal-lb" {
name = "${local.resource_prefix}-internal-lb"
location = azurerm_resource_group.aks_rg.location
resource_group_name = azurerm_resource_group.aks_rg.name
sku = "Standard"
frontend_ip_configuration {
name = "InternalIPAddress"
private_ip_address = var.aks_internal_lb_ip
private_ip_address_allocation = "Static"
subnet_id = data.terraform_remote_state.net.outputs.aks_subnet_id
}
}
resource "azurerm_lb_backend_address_pool" "aks-internal-lb-be-pool" {
loadbalancer_id = azurerm_lb.aks-internal-lb.id
name = "InternalBackEndAddressPool"
}
对应的aks配置:
resource "azurerm_kubernetes_cluster" "k8s" {
name = "${local.resource_prefix}-k8s"
location = azurerm_resource_group.aks_rg.location
resource_group_name = azurerm_resource_group.aks_rg.name
dns_prefix = local.resource_prefix
private_dns_zone_id = "System"
private_cluster_enabled = true
default_node_pool {
name = "defaultpool"
node_count = 3
vm_size = "Standard_D2s_v3"
vnet_subnet_id = data.terraform_remote_state.net.outputs.aks_subnet_id
availability_zones = [ 1, 2, 3 ]
max_pods = 110
}
identity {
type = "SystemAssigned"
}
network_profile {
network_plugin = "azure"
}
}
这个 LoadBalancer 的用途是什么?你想将它用于入口控制器吗?如果是,则不能使用通过 Terraform 创建的现有 LB。
如果您在 AKS 中创建一个服务,如果您指定 type: LoadBalancer
:
,它将自动在节点资源组中为您创建一个 LoadBalancer
外部负载均衡器:
spec:
type: LoadBalancer
loadBalancerIP: 53.1.1.1
内部负载均衡器:
metadata:
name: internal-app
annotations:
service.beta.kubernetes.io/azure-load-balancer-internal: "true"
# If you use any different Subnet for the Ingress, add this:
service.beta.kubernetes.io/azure-load-balancer-internal-subnet: "apps-subnet"
spec:
type: LoadBalancer
loadBalancerIP: 10.240.0.25
这是文档:External-LB and Internal-LB。
我已经通过 Terraform 配置了一个 AKS 集群。它作为标准部署了一个外部负载均衡器,该负载均衡器配置了一个指向默认池的 VM 规模集的后端池。
我现在想配置第二个(内部)负载均衡器,其后端池指向同一个 VM 规模集。这可能吗?如果是这样,我如何获得对该规模集的引用?以及如何将负载均衡器附加到规模集?
负载均衡器的配置:
resource "azurerm_lb" "aks-internal-lb" {
name = "${local.resource_prefix}-internal-lb"
location = azurerm_resource_group.aks_rg.location
resource_group_name = azurerm_resource_group.aks_rg.name
sku = "Standard"
frontend_ip_configuration {
name = "InternalIPAddress"
private_ip_address = var.aks_internal_lb_ip
private_ip_address_allocation = "Static"
subnet_id = data.terraform_remote_state.net.outputs.aks_subnet_id
}
}
resource "azurerm_lb_backend_address_pool" "aks-internal-lb-be-pool" {
loadbalancer_id = azurerm_lb.aks-internal-lb.id
name = "InternalBackEndAddressPool"
}
对应的aks配置:
resource "azurerm_kubernetes_cluster" "k8s" {
name = "${local.resource_prefix}-k8s"
location = azurerm_resource_group.aks_rg.location
resource_group_name = azurerm_resource_group.aks_rg.name
dns_prefix = local.resource_prefix
private_dns_zone_id = "System"
private_cluster_enabled = true
default_node_pool {
name = "defaultpool"
node_count = 3
vm_size = "Standard_D2s_v3"
vnet_subnet_id = data.terraform_remote_state.net.outputs.aks_subnet_id
availability_zones = [ 1, 2, 3 ]
max_pods = 110
}
identity {
type = "SystemAssigned"
}
network_profile {
network_plugin = "azure"
}
}
这个 LoadBalancer 的用途是什么?你想将它用于入口控制器吗?如果是,则不能使用通过 Terraform 创建的现有 LB。
如果您在 AKS 中创建一个服务,如果您指定 type: LoadBalancer
:
外部负载均衡器:
spec:
type: LoadBalancer
loadBalancerIP: 53.1.1.1
内部负载均衡器:
metadata:
name: internal-app
annotations:
service.beta.kubernetes.io/azure-load-balancer-internal: "true"
# If you use any different Subnet for the Ingress, add this:
service.beta.kubernetes.io/azure-load-balancer-internal-subnet: "apps-subnet"
spec:
type: LoadBalancer
loadBalancerIP: 10.240.0.25
这是文档:External-LB and Internal-LB。