Create a container image with ACS Commit

更新时间:
复制 MD 格式

Use ACS Commit to create a container image from a container running in a Pod and push the image to a specified container image repository.

Limitations

  1. Ensure that you have the required permissions to push images. When you configure imagePullSecrets for a Pod or Commit custom resource, the specified secret must grant permissions to push images.

  2. Submit a Commit only after the Pod is in the Running state.

  3. Only one Commit can be running for the same Pod at a time. After a Commit reaches a terminal state (Succeeded or Failed), submit another Commit.

  4. After a Commit enters the Running state, the task cannot be interrupted by deleting the Commit.

  5. When a Commit completes (reaches Succeeded or Failed status), the cluster retains its metadata for 7 days by default, up to a maximum of 30 days. After this period, the cluster automatically deletes the Commit's metadata. This process does not delete the image artifact.

  6. The tag of the image to push must comply with community specifications for images and can be up to 128 characters in length.

Prerequisites

  1. An ACS cluster or an ACK managed cluster is created.

  2. Install the ack-agent-sandbox-controller component from the Add-ons page of the cluster.

Step 1: Create example resources

Add the image.alibabacloud.com/enable-commit: "true" annotation to the pod to enable the container image commit feature.

  1. Create an imagePullSecret for pushing the image.

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

    Replace the placeholders in the command with actual values.

    1. <acrurl>: The address of the image repository, such as ***-***-registry.cn-hangzhou.cr.aliyuncs.com. In a PPU scenario, ensure that the image repository is accessible over the VPC network.

    2. <username>: the username used to log on to the image repository.

    3. <password>: the password used to log on to the image repository.

  2. Create an example 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
            ephemeral-storage: "40Gi" # Declare the storage space as 40 GiB. You can adjust this value based on your actual needs.
          requests:
            cpu: "4"
            memory: 8Gi
            ephemeral-storage: "40Gi" # Declare the storage space as 40 GiB. You can adjust this value based on your actual needs.

    GPU

    For information about the alibabacloud.com/gpu-model-series configuration, see GPU model series supported by ACS.

    apiVersion: v1
    kind: Pod
    metadata:
      labels:
        # Set compute-class to gpu.
        alibabacloud.com/compute-class: gpu
        alibabacloud.com/gpu-model-series: <The GPU model series supported by ACS, such as 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
            ephemeral-storage: "40Gi" # Declare the storage space as 40 GiB. You can adjust this value based on your actual needs.
          requests:
            cpu: "4"
            memory: 8Gi
            nvidia.com/gpu: 1
            ephemeral-storage: "40Gi" # Declare the storage space as 40 GiB. You can adjust this value based on your actual needs.

Step 2: Push image using Commit

Note

A Commit is a namespace-scoped resource. The Commit resource object must be in the same namespace as its target Pod.

  1. Create a Commit resource object.

    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
      imagePullSecrets:
      - name: push-secret

    The following table describes the key parameters:

    Parameter

    Description

    spec.podName

    The target Pod for the commit operation.

    spec.containerName

    The target container within the Pod.

    spec.image

    The destination for the image artifact. If an image with the same name and tag already exists, it will be overwritten.

    spec.ttl

    This is an optional parameter with a default value of 7 days. It configures automatic garbage collection (GC) to delete completed Commit resource objects. Parameter format examples: 30h, 30m, 30s.

    spec.status.phase

    The execution status of the Commit. Valid values:

    • An empty string ("") indicates the default status.

    • Pending: The commit is queued.

    • Running: The commit request is being processed.

    • Succeeded: The commit completed and the image was pushed.

    • Failed: The commit request failed. Check the Kubernetes event for the error details.

Step 3: Verify the results

  1. Check the status of the Commit.

    kubectl get commit commit-01 -oyaml

    In the command output, a status.phase of Succeeded indicates that the image was pushed.

    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. Check the image information.

    View the push result in the image repository.