我有一個 ECS 集群和一個應用程式負載均衡器。我已經按照
因此,我不斷啟動新 EC2 實體并終止現有實體的 Autoscaling 組

下面是我創建 ALB、偵聽器和 target_group 的 Tarraform 組態檔:
resource "aws_alb" "default" {
name = "${var.app_name}-${var.app_environment}-alb"
load_balancer_type = "application"
internal = true
subnets = var.loadbalancer_subnets
security_groups = [aws_security_group.load_balancer_security_group.id]
}
resource "aws_lb_listener" "default" {
load_balancer_arn = aws_alb.default.arn
port = "80"
protocol = "HTTP"
default_action {
type = "forward"
target_group_arn = aws_lb_target_group.default.arn
}
}
resource "aws_lb_target_group" "default" {
name_prefix = "rushmo"
port = 80
protocol = "HTTP"
vpc_id = var.vpc_id
target_type = "instance"
health_check {
healthy_threshold = "2"
unhealthy_threshold = "5"
interval = "300"
port = "traffic-port"
path = "/"
protocol = "HTTP"
matcher = "200,301,302"
}
}
resource "aws_autoscaling_group" "default" {
name = "${var.app_name}-${var.app_environment}-ASG"
desired_capacity = 1
health_check_type = "ELB"
health_check_grace_period = 600 # 10 min
launch_configuration = aws_launch_configuration.default.name
max_size = 1
min_size = 1
target_group_arns = [aws_lb_target_group.default.arn]
termination_policies = ["OldestInstance"]
vpc_zone_identifier = var.application_subnets
protect_from_scale_in = true
}
注意:如果我從目標組手動取消注冊埠 80 上的目標,則解決了不斷終止和啟動新實體的問題,但我不明白我做錯了什么以及為什么此埠 80 顯示為已注冊的目標不僅是臨時埠范圍
uj5u.com熱心網友回復:
我認為問題是由于:
health_check_type = "ELB"
這使得 ASG 可以在您的實體的埠 80 上使用 ALB 的運行狀況檢查。但是,由于您使用的是 ECS,健康檢查應該只用于您的容器,而不是實體本身。因此它應該是:
health_check_type = "EC2"
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/367218.html
