确保在 AWS 帐户中启用了 Network Load Balancer。
确保网络负载均衡器 (NLB) 和 Application Load Balancer (ALB) 都已正确地配置和设置,并已放置在公共子网中。
确保您的目标组映射到正确的路由表,或者将所有的实例放到与 ALB 和 NLB 相同的子网中。
如果您正在使用 Amazon ECS 或 Amazon EKS,请确保您的服务/任务定义已针对负载均衡器进行了正确的配置和设置。
如果您正在使用自定义 AMI,请确保在 AMI 上正确配置和设置您的网络连接。
您还可以将 access logs 用于 ALB 和 NLB 以了解有关请求失败的更多信息。
代码示例:
resource "aws_lb" "example" {
name = "example"
internal = true
type = "network"
subnets = [
aws_subnet.example_a.id,
aws_subnet.example_b.id,
]
load_balancer_type = "network"
}
resource "aws_lb_target_group" "example" {
name_prefix = "example-"
port = 80
protocol = "TCP"
vpc_id = aws_vpc.example.id
}
resource "aws_lb_listener" "example" {
load_balancer_arn = aws_lb.example.arn
port = 80
default_action {
type = "forward"
target_group_arn = aws_lb_target_group.example.arn
}
}
resource "aws_network_interface" "example" {
subnet_id = aws_subnet.example_a.id
tags = {
Name = "example"
}
}
resource "aws_lb_target_group_attachment" "example" {
target_group_arn = aws_lb_target_group.example.arn
target_id = aws_network_interface.example.id
port = 80