首页 > 解决方案 > 是否可以将 Codedeploy BlueGreen 部署到 ECS 使用运行状况检查数据?

问题描述

我无法做到这一点。我在我的 NLB 的两个目标组上配置了运行状况检查,它们报告运行状况良好,但即使切换到的目标组永远不会变得健康,部署也会发生并成功。

我当然可以使用警报和基于 lambda 的测试来回滚,但我不确定我是否可以创建一个针对当前非服务产品目标组而不是当前服务产品目标组的警报,以便回滚部署适当地。

似乎除了 CodeDeployDefault.ECSAllAtOnce 之外的任何东西都不能用于 ECS 绿色/蓝色,而且我还看到根本不可能在 ECS 部署配置中定义最小健康主机,这是否意味着 CodeDeploy 不考虑部署 ECS 时的健康状况?

这是我的 codedeploy terraform:

resource "aws_codedeploy_deployment_group" "deployment_group" {
  app_name               = aws_codedeploy_app.application.name
  deployment_group_name  = "${var.project_name}-deployment-group"
  service_role_arn       = aws_iam_role.codedeploy_role.arn
  deployment_config_name = "CodeDeployDefault.ECSAllAtOnce"

  # Automatically rollback on failure, alarm, or request.
  # See: https://docs.aws.amazon.com/codedeploy/latest/APIReference/API_AutoRollbackConfiguration.html
  auto_rollback_configuration {
    enabled = "true"
    events = ["DEPLOYMENT_FAILURE", "DEPLOYMENT_STOP_ON_ALARM", "DEPLOYMENT_STOP_ON_REQUEST"]
  }

  blue_green_deployment_config {
    # See: https://docs.aws.amazon.com/codedeploy/latest/APIReference/API_DeploymentReadyOption.html
    deployment_ready_option {
      action_on_timeout = "CONTINUE_DEPLOYMENT"
    }

    terminate_blue_instances_on_deployment_success {
      action = "TERMINATE"

      # How many minutes to wait before terminating old instances
      termination_wait_time_in_minutes = 1
    }
  }

  # These settings are required for ECS deployments.
  deployment_style {
    deployment_option = "WITH_TRAFFIC_CONTROL"
    deployment_type   = "BLUE_GREEN"
  }

  # What to deploy
  ecs_service {
    cluster_name = aws_ecs_cluster.cluster.name
    service_name = aws_ecs_service.service.name
  }

  load_balancer_info {
    target_group_pair_info {
      # The path used by a load balancer to route production traffic when an Amazon ECS deployment is complete.
      prod_traffic_route {
        listener_arns = [aws_lb_listener.listener.arn]
      }

      # Blue group is the original group at first.
      target_group {
        name = aws_lb_target_group.blue_group.name
      }

      # Green group is the one that gets switched to at first.
      target_group {
        name = aws_lb_target_group.green_group.name
      }
    }
  }
}

这是我的目标群体:

resource "aws_lb_target_group" "blue_group" {
  name        = "${var.project_name}-${var.stage}-b"
  port        = 8080
  protocol    = "TCP"
  target_type = "ip"
  vpc_id = var.vpc_id

  health_check {
      path = var.nlb_healthcheck_path
      port = var.container_port
      protocol = "HTTP"
      healthy_threshold = 2
      unhealthy_threshold = 2
      interval = 10
   }

  stickiness {
      enabled = false
      type = "lb_cookie"
  }
}

resource "aws_lb_target_group" "green_group" {
  name        = "${var.project_name}-${var.stage}-g"
  port        = 8080
  protocol    = "TCP"
  target_type = "ip"
  vpc_id = var.vpc_id

  health_check {
      path = aws_lb_target_group.blue_group.health_check[0].path
      port = aws_lb_target_group.blue_group.health_check[0].port
      protocol = aws_lb_target_group.blue_group.health_check[0].protocol
      healthy_threshold = aws_lb_target_group.blue_group.health_check[0].healthy_threshold
      unhealthy_threshold = aws_lb_target_group.blue_group.health_check[0].unhealthy_threshold
      interval = aws_lb_target_group.blue_group.health_check[0].interval
   }

  stickiness {
      enabled = false
      type = "lb_cookie"
  }
}

标签: amazon-web-servicesterraformamazon-ecsaws-code-deploy

解决方案


推荐阅读