可通过ACS Commit 将Pod中运行的容器制作成容器镜像,并推送至指定容器镜像仓库。
前提条件
使用限制
当前仅支持ACS通用算力使用 Commit 能力。
确保镜像推送权限。使用 Pod 的
imagePullSecrets用于推送镜像,请确保相关 Secret 有推送镜像的权限。Pod状态为 Running 之后才可提交 Commit。
同一个Pod,只能同时存在一个运行中的 Commit。Commit 达到终态(成功或失败)后,可再次提交 Commit。
Commit Running 之后,无法通过删除 Commit 中断任务。
Commit 完成(成功或失败)后,集群内元数据默认保留7天,最大保存时间30天。过期后则自动删除 Commit元数据,但不会删除镜像产物。
推送镜像的Tag, 需满足社区镜像规范,最大128个字符。
步骤一:创建示例资源
创建推送镜像所使用的
imagePullSecret。kubectl create secret docker-registry push-secret --docker-server=<acrurl> --docker-username=<username> --docker-password=<password>请替换命令中的占位符为实际值。
<acrurl>:镜像仓库地址,如***-***-registry.cn-hangzhou.cr.aliyuncs.com。<username>:镜像仓库用户名。<password>:镜像仓库密码。
创建示例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推送镜像
Commit是Namespace 维度资源,Commit资源需要和Commit操作的Pod在同一个命名空间。
创建
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.podNameCommit操作关联的Pod。
spec.containerNameCommit操作关联的Pod中的目标容器。
spec.imageCommit的目标镜像产物,会覆盖同名镜像。
spec.ttl可选参数,默认为7天。Commit资源对象可设置自动GC,删除已完成的Commit对象。参数格式示例:
30h、30m、30s。spec.status.phaseCommit执行状态,取值:
"":默认状态。Pending:Commit请求排队中。Running:Commit请求已提交。Succeeded:Commit请求已完成,目标镜像已经推送。Failed:Commit处理失败,可通过K8s Event查看错误详情。
spec.status.conditionsCommit 执行过程详细信息,包括各阶段耗时,镜像大小等。有以下几种类型:
PullBaseImage: 下载容器镜像。CommitContainer: 对容器执行 Commit。此阶段,容器会被Pause。PushCommittedImage: 推送镜像至目标仓库。
步骤三:结果验证
查看
Commit状态。kubectl get commit commit-01 -oyaml预期输出中,若
status.phase为Succeeded则说明镜像已经推送成功,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"查看镜像信息。
可在镜像仓库,查看镜像推送结果。