您可以通过fargate中的相同容器将期望计数缩减为0 [英] can you scale down desiredcount to 0 via same container in fargate

查看:62
本文介绍了您可以通过fargate中的相同容器将期望计数缩减为0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Fargate服务,其中有一个任务在运行容器.因此,我的容器是一个定制管道,该管道基于SQS计数运行.因此,如果所有记录都已处理,那么我将从容器中停止管道.因此,我想知道的是,我可以将服务的期望计数设置为0,而不是停止管道吗?(此服务是此容器任务的父级)

I have a fargate service where a task running a container. So, my container is a custom made pipeline, which runs based on SQS count. So, if all the records are processed then I stop the pipeline from the container. So, what I'm wondering, instead of stopping the pipeline, can I set the desired count of the service to 0?(this service is the parent of this container's task)

推荐答案

是的,您可以在过程完成后将需求计数设置为零,但是您无需考虑任何事情.

Yes, you can set desire count to zero once the process complete, but there are few things that you need to consider.

  • 您的节点进程应在完成操作后退出
  • Dockerfile应该具有有效的入口点aws-cli
  • Fargate服务应必须执行ecs服务更新操作

例如Dockerfile

For example Dockerfile

FROM node:alpine
RUN apk add --no-cache python py-pip

RUN pip install awscli
RUN aws --version
WORKDIR /app
COPY app.js .
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
ENTRYPOINT /entrypoint.sh

入口点,它将处理nodejs进程,并在SQS中完成nodejs进程时将服务计数设置为0.

entrypoint that will deal with nodejs process and set service count to 0 when the nodejs process completed from SQS.

#!/bin/sh
# start the node process, but it should exit once it processes all SQS
node app.js
# once process is done, we are good to scale down the service
aws ecs update-service --cluster my-cluster --region us-west-2 --service my-http-service --desired-count 0

一个示例节点进程,app.js将在1分钟后退出

An example node process that will exit after 1 minute, app.js

function intervalFunc() {
  console.log('Container will stop  in 1 minutes');
}

setInterval(intervalFunc, 1500);
setTimeout((function() {
    return process.exit(0);
}), 60000);

因此Docker映像起着重要作用,节点进程应退出,否则它将继续运行.

So Docker image play an important role and the node process should exit otherwise it will keep running.

这篇关于您可以通过fargate中的相同容器将期望计数缩减为0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆