我有一个使用Fargate在AWS ECS中运行的容器。
我在下面的Terraform中注册它,并将主机名添加到服务发现中。我看到它将其添加到route53中,然后将其删除,我认为这是由于它无法通过运行状况检查。
失败 启动容器时出现以下错误:
company / cmd createServer net.list company.qcap.prod:50031监听tcp: 在10.0.0.2:53上查找company.qcap.prod:没有这样的主机
在主机在Route53中注册之前,我的服务无法侦听该地址,但是如果Route53无法通过运行状况检查,则我的Route53会删除DNS条目。
有没有办法告诉任务等到添加该条目然后进行运行状况检查?
以下是我用于该服务的Terraform
data "template_file" "company" {
template = file("./templates/ecs/company.json.tpl")
vars = {
app_port = 50010
fargate_cpu = var.fargate_cpu
fargate_memory = var.fargate_memory
aws_region = var.region
}
}
resource "aws_ecs_task_definition" "company" {
family = "company-app-task"
execution_role_arn = aws_iam_role.ecs_task_execution_role.arn
network_mode = "awsvpc"
requires_compatibilities = [
"FARGATE"]
cpu = var.fargate_cpu
memory = var.fargate_memory
container_definitions = data.template_file.company.rendered
}
resource "aws_ecs_service" "company-service" {
name = "company-service"
cluster = aws_ecs_cluster.main.id
task_definition = aws_ecs_task_definition.company.id
desired_count = var.app_count
launch_type = "FARGATE"
network_configuration {
security_groups = [
aws_security_group.ecs_tasks.id
]
subnets = module.vpc.private_subnets
assign_public_ip = true
}
service_registries {
container_name = "company"
registry_arn = aws_service_discovery_service.company.arn
}
lifecycle {
create_before_destroy = true
}
depends_on = [
aws_iam_role_policy_attachment.ecs_task_execution_role
]
}
resource "aws_service_discovery_service" "company" {
name = "company"
dns_config {
namespace_id = aws_service_discovery_private_dns_namespace.qcap_prod_sd.id
routing_policy = "MULTIVALUE"
dns_records {
ttl = 10
type = "A"
}
}
health_check_custom_config {
failure_threshold = 10
}
}