【问题标题】:Update K8S container's imageid whitout change image's name or tag在不更改镜像名称或标签的情况下更新 K8S 容器镜像 id
【发布时间】:2020-01-09 15:26:01
【问题描述】:

在我的 deployment.yaml 中,图像的分配方式如下

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

在 nexus 中,我更新了图像,但没有更改名称和标签。 我想在k8s pod中使用新的图像。所以我尝试使用

imagePullPolicy: "Always" + delete the old pod

现在在节点上,docker images 可以显示图像的新哈希。 在仪表板中,我可以看到事件“拉图像”成功。 但是

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

显示新创建的 pod 仍在使用旧的图像哈希 id。

如何在不更改图像名称或标签的情况下更新图像?

更新节目:

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",

以及节点上的 docker 镜像:

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

45f6b42ab2f76 和 49889fd96652 不同。

我使用本地环境和 kubectl 版本

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 图像 --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

【问题讨论】:

  • kubectl get pod -n k8s-demo k8s-pod-build-32-d4794d44-zrgvh -o json 的输出是什么?你是如何决定它使用旧图像的?
  • 这能回答你的问题吗? Kubernetes how to make Deployment to update image
  • ...但我见过的最佳实践是给每个构建一个唯一的标签(也许让您的 CI 系统标签构建带有提交 ID 或日期戳);那么这不是问题,而且如果构建不起作用,您可以轻松回滚。
  • 您使用的是本地环境还是本地环境?什么K8s版本?
  • @Shashank V ,我发现 45f6b42ab2f76 是摘要,49889fd96652 是图像ID。所以也许它更新成功了。

标签: kubernetes


【解决方案1】:

您正在比较 docker image iddigest,它们不是一回事。 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 在你的情况下。

【讨论】:

  • docker inspect --format='{{.RepoDigests}}' 49889fd96652 --------shows ----->45f6b42ab2f7629cf8032c09c78ccf7627ca6e71d5c15173f81217100f87eecb-----是否意味着更新成功?
  • 是的。摘要匹配。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-10-22
  • 1970-01-01
  • 2017-04-09
  • 2022-11-25
  • 2016-03-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多