问题描述
我正在尝试使用ecs-cli compose在Amazon ECS上管理我的服务和任务.
I am trying to use ecs-cli compose to manage my services and tasks on Amazon ECS.
我找不到使用service up
命令通过应用程序负载平衡器创建新服务的方法(即使该负载平衡器已经存在).
I'm unable to find a way using the service up
command to create a new service with an application load balancer (even when that load balancer already exists).
使用service create
似乎可行,但是该API与service up
API不同,并且我不确定如何使用create
同样地指定参数.而且通常最好只使用up
命令以保持一致性.文档非常分散,做相同的事情有很多不同的方法,只是想知道这里有什么最佳实践.任何建议,不胜感激.
This seems possible with service create
, but the API is different from the service up
API, and I'm not sure how to specify params in the same way with create
. And it would generally be preferable to use just the up
command for consistency. The documentation is pretty scattered, there's many different ways to do the same things, just wondering what best practice is here. Any suggestions greatly appreciated.
值得一提的是,只要我有一个现有的任务定义,并且在指定负载均衡器的同时通过Amazon AWS GUI创建服务,一切都对我有用.所以我正在考虑将我所有的compose配置都移到task-definition.json中,并直接与aws ecs
cli一起使用.
Worth noting, everything is working for me, so long as I have an existing task definition and I create my service through the Amazon AWS GUI while specifying the load balancer. So I'm thinking about moving all my compose config into a task-definition.json and use it directly with aws ecs
cli.
我有一个有效的docker-compose.yml
文件:
# docker-compose.yml
version: "3"
services:
application:
image: ${IMAGE_ARN}
command: npm start
ports:
- "8000:8000"
nginx:
image: ${IMAGE_ARN}
ports:
- "80:80"
以及随附的ecs-params.yml
文件:
# ecs-params.yml
version: 1
task_definition:
task_role_arn: ${ROLE_ARN}
task_execution_role: ${ROLE_ARN}
ecs_network_mode: awsvpc
task_size:
mem_limit: 0.5GB
cpu_limit: 256
container_definitions:
- name: application
- name: nginx
run_params:
network_configuration:
awsvpc_configuration:
assign_public_ip: ENABLED
subnets:
- ${SUBNET_1_ID}
- ${SUBNET_2_ID}
security_groups:
- ${SECURITY_GROUP_ID}
我运行来启动该服务的命令是:
The command that I run to bring the service up is:
ecs-cli compose service up \
--file docker-compose.yaml \
--ecs-params ecs-params.yaml \
--project-name service-name
通过该命令指定负载均衡器配置的任何方式吗?
Any way to specify the load balancer configuration through that command?
推荐答案
似乎最新的ecs-cli
版本确实支持服务启动时的负载均衡器配置.
It seems like latest ecs-cli
version does support load balancer configuration with service up.
您是否尝试提供--target-group-arn
选项?假设您已经创建了ALB和目标组来关联ECS服务.这是我刚刚测试过的示例命令.
Have you tried providing --target-group-arn
option?. Assuming you have already created ALB and Target Group to associate ECS service. Here is sample command I just tested.
ecs-cli compose --file docker-compose.yaml --project-name nginx \
--ecs-params ecs-params.yaml service up \
--target-group-arn "arn:aws:elasticloadbalancing:us-east-1:xxxxxxxx:targetgroup/awsvpc-nginx/2bf8921935c827bd" \
--container-name nginx --container-port 80
注意-
-
target-group-arn
,container-name
和container-port
选项对于负载平衡器关联是必需的,并且必须在service up
之后的命令中提供. - 我看到您正在尝试使用
awsvpc
模式执行任务.我不确定您是否要尝试启动EC2或Fargate类型的启动容器. - 如果您确实希望使用
awsvpc
模式,请确保您的负载均衡器目标组已创建了类型为ip
而不是instance
的目标. - 如果您使用的是EC2启动类型,但使用
awsvpc
模式,请确保EC2 AMI是Amazon-ECS优化AMI.如果您使用的是Fargate类型,则您的assign_public_ip
应该为DISABLED
.
target-group-arn
,container-name
andcontainer-port
options are mandatory for load balancer association and they have to be provided in command afterservice up
.- I see you are trying to use
awsvpc
mode for the tasks. I am not sure you are trying to bring up EC2 or Fargate type launch container. - If you do want
awsvpc
mode then please make sure your load balancer target group has target created with typeip
instead ofinstance
. - If you are on EC2 launch type but with
awsvpc
mode then please make sure EC2 AMI is Amazon-ECS Optimized AMI. If you are on Fargate type then yourassign_public_ip
shouldDISABLED
.
让我知道您的反馈意见.
Do let me know your feedback.
参考- https://docs.aws.amazon .com/AmazonECS/latest/developerguide/cmd-ecs-cli-compose-service.html
https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-networking.html
这篇关于ecs-cli通过负载均衡器组成服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!