如果 ECS 集群仍在引用任何 ECR 映像,请避免使其过期

发布于 2025-01-11 01:12:00 字数 338 浏览 0 评论 0原文

我们正在实施生命周期策略来清理旧的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

手心的海 2025-01-18 01:12:00

不幸的是,使用生命周期规则来管理镜像对于 AWS 来说并不理想。

  • 多平台映像(amd64 + arm64)通过具有顶级元映像在注册表中进行管理,该元映像根据平台指向其他映像(这有点简化)。当您标记图像时,它仅标记顶级元图像,而不标记较低级别的元图像。因此,可能会意外删除图像。
  • 正如您所发现的,即使图像在某处被引用,也可以被删除。

我没有使用生命周期规则,而是使用一个简单的脚本,其中包含我想要的任何逻辑。您可以运行过滤器来查看存在哪些 ECS 服务并正在使用该映像,然后排除任何返回空的位置。如果所有内容都在同一个帐户中,这会简单得多。

换句话说,不要让服务将标签推送到图像,而是让删除脚本明确确认没有删除正在使用的图像。那么您就不必担心有多少环境正在运行它。

Unfortunately using lifecycle rules to manage images is just not ideal with AWS.

  • Multiplatform images (amd64 + arm64) are managed in registries by having a top level meta image that points to other images depending on platform (this is a bit of a simplification). When you tag your image it only tags the top level meta one, not the lower level ones. As such it's possible to accidentally erase images.
  • As you've discovered images can be erased even if they are referenced somewhere.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文