使用ACS Commit制作容器镜像

更新时间:
复制为 MD 格式

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

前提条件

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

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

使用限制

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

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

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

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

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

  6. 推送镜像的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。

    CPU算力

    apiVersion: v1
    kind: Pod
    metadata:
      labels:
        alibabacloud.com/compute-class: performance
        alibabacloud.com/compute-qos: default
        alibabacloud.com/acs: 'true'
      annotations:
        image.alibabacloud.com/enable-commit: "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

    GPU算力

    关于alibabacloud.com/gpu-model-series的配置,请参见ACS支持的GPU规格族

    apiVersion: v1
    kind: Pod
    metadata:
      labels:
        # 指定compute-classgpu类型
        alibabacloud.com/compute-class: gpu
        alibabacloud.com/gpu-model-series: <ACS支持的GPU规格族,如GU8TF等>
        alibabacloud.com/compute-qos: default
      annotations:
        image.alibabacloud.com/enable-commit: "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
            nvidia.com/gpu: 1
          requests:
            cpu: "4"
            memory: 8Gi
            nvidia.com/gpu: 1

步骤二:使用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查看错误详情。

步骤三:结果验证

  1. 查看Commit状态。

    kubectl get commit commit-01 -oyaml

    预期输出中,若status.phaseSucceeded则说明镜像已经推送成功。

    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"
      phase: Succeeded
      startTime: "2025-12-05T02:23:12Z"
  2. 查看镜像信息。

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