1

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
clara
  • 182
  • 1
  • 2
  • 13
  • 1
    What is the output of `kubectl get pod -n k8s-demo k8s-pod-build-32-d4794d44-zrgvh -o json`? How did you decide it was using old image? – Shashank V Jan 07 '20 at 09:22
  • 1
    Does this answer your question? [Kubernetes how to make Deployment to update image](https://stackoverflow.com/questions/40366192/kubernetes-how-to-make-deployment-to-update-image) – David Maze Jan 07 '20 at 12:20
  • ...but the best practice I've seen is to give a unique tag to each build (maybe have your CI system tag builds with a commit ID or date stamp); then this isn't a problem, plus you can easily roll back if a build doesn't work. – David Maze Jan 07 '20 at 12:21
  • Are you using On-Prem or local env? What K8s version? – PjoterS Jan 07 '20 at 12:57
  • @Shashank V ,I found 45f6b42ab2f76 is the digest and 49889fd96652 is image id.So maybe it update successfully. – clara Jan 09 '20 at 07:02

1 Answers1

0

You are comparing docker image id and it's digest which are not the same thing. image id is the hash of the JSON config of the local image. digest is the hash of registry manifest.

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 here is the digest.

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

49889fd96652 here is the image id.

If you want to see the digest of a local image, you can use

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

docker inspect --format='{{index .RepoDigests 0}} nexus.company.local:5000/e7bld-cdc-32bit:2.0 in your case.

Shashank V
  • 10,007
  • 2
  • 25
  • 41
  • docker inspect --format='{{.RepoDigests}}' 49889fd96652 -------shows ----->45f6b42ab2f7629cf8032c09c78ccf7627ca6e71d5c15173f81217100f87eecb-----does it mean update successfully? – clara Jan 10 '20 at 07:12
  • Yes. The digest matches. – Shashank V Jan 10 '20 at 08:45