使用ACS Commit制作容器镜像

可通过ACS Commit 将Pod中运行的容器制作成容器镜像,并推送至指定容器镜像仓库。

前提条件

  1. 已创建ACS集群ACK托管集群

  2. 在集群组件管理中安装 ack-agent-sandbox-controller 组件。

  3. 提交工单申请开启功能白名单,当前邀测发布。

使用限制

  1. 当前仅支持ACS通用算力使用 Commit 能力。

  2. 确保镜像推送权限。使用 Pod 的 imagePullSecrets 用于推送镜像,请确保相关 Secret 有推送镜像的权限。

  3. Pod状态为 Running 之后才可提交 Commit。

  4. 同一个Pod,只能同时存在一个运行中的 Commit。Commit 达到终态(成功或失败)后,可再次提交 Commit。

  5. Commit Running 之后,无法通过删除 Commit 中断任务。

  6. Commit 完成(成功或失败)后,集群内元数据默认保留7天,最大保存时间30天。过期后则自动删除 Commit元数据,但不会删除镜像产物。

  7. 推送镜像的Tag, 需满足社区镜像规范,最大128个字符。

步骤一:创建示例资源

  1. 创建推送镜像所使用的imagePullSecret

    kubectl create secret docker-registry push-secret --docker-server=<acrurl> --docker-username=<username> --docker-password=<password>

    请替换命令中的占位符为实际值。

    1. <acrurl>:镜像仓库地址,如***-***-registry.cn-hangzhou.cr.aliyuncs.com

    2. <username>:镜像仓库用户名。

    3. <password>:镜像仓库密码。

  2. 创建示例Pod。

    apiVersion: v1
    kind: Pod
    metadata:
      labels:
        alibabacloud.com/compute-class: performance
        alibabacloud.com/compute-qos: default
        alibabacloud.com/acs: 'true'
      name: commit-01
      namespace: default
    spec:
      imagePullSecrets:
      - name: push-secret
      containers:
      - image: registry.openanolis.cn/openanolis/nginx:1.14.1-8.6
        name: main
        resources:
          limits:
            cpu: "4"
            memory: 8Gi
          requests:
            cpu: "4"
            memory: 8Gi

步骤二:使用Commit推送镜像

说明

CommitNamespace 维度资源,Commit资源需要和Commit操作的Pod在同一个命名空间。

  1. 创建Commit资源对象。

    apiVersion: agents.kruise.io/v1alpha1
    kind: Commit
    metadata:
      name: commit-01 
      namespace: default
    spec:
      podName: commit-01  
      containerName: main  
      image: ***-***-registry.cn-hangzhou.cr.aliyuncs.com/commit/nginx:commit-01
      ttl: 72h

    主要参数说明:

    参数项

    说明

    spec.podName

    Commit操作关联的Pod。

    spec.containerName

    Commit操作关联的Pod中的目标容器。

    spec.image

    Commit的目标镜像产物,会覆盖同名镜像。

    spec.ttl

    可选参数,默认为7天。Commit资源对象可设置自动GC,删除已完成的Commit对象。参数格式示例:30h30m30s

    spec.status.phase

    Commit执行状态,取值:

    • "":默认状态。

    • Pending:Commit请求排队中。

    • Running:Commit请求已提交。

    • Succeeded:Commit请求已完成,目标镜像已经推送。

    • Failed:Commit处理失败,可通过K8s Event查看错误详情。

    spec.status.conditions

    Commit 执行过程详细信息,包括各阶段耗时,镜像大小等。有以下几种类型:

    • PullBaseImage: 下载容器镜像。

    • CommitContainer: 对容器执行 Commit。此阶段,容器会被Pause。

    • PushCommittedImage: 推送镜像至目标仓库。

步骤三:结果验证

  1. 查看Commit状态。

    kubectl get commit commit-01 -oyaml

    预期输出中,若status.phaseSucceeded则说明镜像已经推送成功,status.conditions字段包含各个阶段的详细信息。

    apiVersion: agents.kruise.io/v1alpha1
    kind: Commit
    metadata:
      annotations:
        alibabacloud.com/instance-id: acs-8vb00987g6o23un9gvs6
      creationTimestamp: "2025-12-05T02:23:12Z"
      finalizers:
      - agents.kruise.io/commit
      generation: 1
      name: commit-01
      namespace: default
      resourceVersion: "22050"
      uid: c13ae054-a029-46e3-bfc5-011db3fd5d9f
    spec:
      containerName: main
      image: ***-***-registry.cn-hangzhou.cr.aliyuncs.com/commit/nginx:commit-01
      podName: commit-01
      ttl: 72h
    status:
      commitID: ***
      completionTime: "2025-12-05T02:23:15Z"
      conditions:
      - lastTransitionTime: "2025-12-05T02:23:13Z"
        message: Pull base image for container main successfully
        reason: PullBaseImageSuccess
        status: "True"
        type: PullBaseImage
      - lastTransitionTime: "2025-12-05T02:23:14Z"
        message: 'Commit container main to image ***-***-registry.cn-hangzhou.cr.aliyuncs.com/commit/nginx:commit-01
          successfully, commit image size: 201665007,commit image usage: 569225216'
        reason: CommitContainerSuccess
        status: "True"
        type: CommitContainer
      - lastTransitionTime: "2025-12-05T02:23:15Z"
        message: Push image ***-***-registry.cn-hangzhou.cr.aliyuncs.com/commit/nginx:commit-01
          successfully
        reason: PushCommittedImageSuccess
        status: "True"
        type: PushCommittedImage
      phase: Succeeded
      startTime: "2025-12-05T02:23:12Z"
  2. 查看镜像信息。

    可在镜像仓库,查看镜像推送结果。