首页 > 解决方案 > Update K8S container's imageid whitout change image's name or tag

问题描述

In my deployment.yaml .the image is assigned like

- image: nexus.company.local:5000/company-ubuntu-32bit:2.0

In nexus, I update the image,but didn't change name and tag. I want to use the new image in k8s pod.So I try to use

imagePullPolicy: "Always" + delete the old pod

Now on the node, docker images can show the new hash of image. And in dashboard,I can see the event "pull image" successfully. But

kubectl get pod -n k8s-demo k8s-pod-build-32-d4794d44-zrgvh -o json

show that the new created pod is still using old image hash id.

How can I update the image without change the image's name or tag?

uupdate the shows:

kubectl get pod -n k8s-demo k8s-pod-build-32-6fbb6bf5cc-dtg4f -o json
"containerStatuses": [
            {
                "containerID": "docker://ef57cbdf31256556fbeda5df4247591ea74ddb71ca0aec512278079e6badc201",
                "image": "nexus.company.local:5000/e7bld-cdc-32bit:2.0",
                "imageID": "docker-pullable://nexus.company.local:5000/e7bld-cdc-32bit@sha256:45f6b42ab2f7629cf8032c09c78ccf7627ca6e71d5c15173f81217100f87eecb",

and the docker image on node:

docker images
REPOSITORY                                   TAG                 IMAGE ID       CREATED             SIZE
nexus.company.local:5000/e7bld-cdc-32bit   2.0                 49889fd96652        4 days ago          1.29GB

45f6b42ab2f76 AND 49889fd96652 is different.

I use local env,and the kubectl version

Client Version: version.Info{Major:"1", Minor:"16", GitVersion:"v1.16.2", GitCommit:"c97fe5036ef3df2967d086711e6c0c405941e14b", GitTreeState:"clean", BuildDate:"2019-10-15T19:18:23Z", GoVersion:"go1.12.10", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"16", GitVersion:"v1.16.2", GitCommit:"c97fe5036ef3df2967d086711e6c0c405941e14b", GitTreeState:"clean", BuildDate:"2019-10-15T19:09:08Z", GoVersion:"go1.12.10", Compiler:"gc", Platform:"linux/amd64"}

docker images --digests

REPOSITORY                                   TAG                 DIGEST                                                                    IMAGE ID            CREATED             SIZE
nexus.company.local:5000/e7bld-cdc-32bit   2.0                 sha256:45f6b42ab2f7629cf8032c09c78ccf7627ca6e71d5c15173f81217100f87eecb   49889fd96652        5 days ago          1.29GB

标签: kubernetes

解决方案


您正在比较 dockerimage id和它digest不是一回事。image id是本地图像的 JSON 配置的哈希值。digest是注册表清单的哈希值。

kubectl get pod -n k8s-demo k8s-pod-build-32-6fbb6bf5cc-dtg4f -o json
"containerStatuses": [
            {
                "containerID": "docker://ef57cbdf31256556fbeda5df4247591ea74ddb71ca0aec512278079e6badc201",
                "image": "nexus.company.local:5000/e7bld-cdc-32bit:2.0",
                "imageID": "docker-pullable://nexus.company.local:5000/e7bld-cdc-32bit@sha256:45f6b42ab2f7629cf8032c09c78ccf7627ca6e71d5c15173f81217100f87eecb"

45f6b42ab2f7629cf8032c09c78ccf7627ca6e71d5c15173f81217100f87eecb这是摘要。

docker images
REPOSITORY                                   TAG                 IMAGE ID       CREATED             SIZE
nexus.company.local:5000/e7bld-cdc-32bit   2.0                 49889fd96652        4 days ago          1.29GB

49889fd96652这是图像ID。

如果要查看本地图像的摘要,可以使用

docker inspect --format='{{index .RepoDigests 0}} <image_name>'

docker inspect --format='{{index .RepoDigests 0}} nexus.company.local:5000/e7bld-cdc-32bit:2.0在你的情况下。


推荐阅读