如果 ECS 集群仍在引用任何 ECR 映像,请避免使其过期
我们正在实施生命周期策略来清理旧的 ECR 映像,但我们想要 避免在 Fargate ECS 集群仍在引用任何映像时使该映像过期。我们怎样才能最好地做到这一点?
我正在考虑添加一个由蓝绿开关设置和取消设置的“实时”标签,但存在一个问题 - 我们的 AWS CodePipeline 中的 2 个或更多环境可能使用相同的映像,因此我需要实现一些一种引用计数。
有没有更好的方法,或者我应该采用这种方法?
We are implementing lifecycle policies to clean up old ECR images but we want to avoid expiring any image if a Fargate ECS cluster is still referencing it. How can we best do that?
I am thinking about adding a "live" tag that is being set and unset by the Blue-Green Switch, but there is a problem - 2 or more environments in our AWS CodePipeline might be using the same image so I would need to implement some kind of reference counting.
Is there a better way, or should I go with this approach?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不幸的是,使用生命周期规则来管理镜像对于 AWS 来说并不理想。
我没有使用生命周期规则,而是使用一个简单的脚本,其中包含我想要的任何逻辑。您可以运行过滤器来查看存在哪些 ECS 服务并正在使用该映像,然后排除任何返回空的位置。如果所有内容都在同一个帐户中,这会简单得多。
换句话说,不要让服务将标签推送到图像,而是让删除脚本明确确认没有删除正在使用的图像。那么您就不必担心有多少环境正在运行它。
Unfortunately using lifecycle rules to manage images is just not ideal with AWS.
Instead of using lifecycle rules I use a simple script, which in turn includes any logic I want. You can run a filter to see what ECS services exist and are using the image and then exclude any where that comes back empty. This is much simpler if everything is in the same account.
To put this another way- instead of having your services push tags to your images, have your deletion script explicitly confirm that no images which are being used get deleted. Then you don't have to worry about how many environments are running it.