You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

能否在OpenShift adm镜像清理时跳过指定镜像?

OpenShift镜像清理:跳过指定镜像的方法

当然可以在清理OpenShift集成镜像仓库时跳过部分镜像,oc adm prune images命令提供了多种实用方式来实现:

  • 按标签保留镜像
    使用--keep-tags参数指定需要保留的镜像标签,命令会跳过所有匹配该标签的镜像,不受其他清理规则限制。示例:

    oc adm prune images --registry-url=<url> --keep-tag-revisions=1 --keep-younger-than=1s --keep-tags="stable,prod"
    

    上述命令会保留所有带有stable或prod标签的镜像。

  • 按注解保留镜像
    先给需要保护的镜像添加注解(比如openshift.io/keep-image: "true"),再使用--keep-annotated参数执行清理:

    oc adm prune images --registry-url=<url> --keep-tag-revisions=1 --keep-younger-than=1s --keep-annotated
    

    所有带有该指定注解的镜像都会被跳过清理。

  • 按镜像ID/名称精准保留
    若需要精准跳过特定镜像,可先筛选出要保留的镜像列表,再通过--keep-images参数传入:

    1. 生成要保留的镜像列表文件:
      oc get images -o name | grep "my-critical-image" > keep-images.txt
      
    2. 执行清理命令:
      oc adm prune images --registry-url=<url> --keep-tag-revisions=1 --keep-younger-than=1s --keep-images=@keep-images.txt
      

这些参数可以组合使用,根据实际场景灵活搭配。

内容的提问来源于stack exchange,提问作者PGS

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.24 13:54:37