kubernetes - 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
解决方案
您正在比较 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
在你的情况下。
推荐阅读
- kubernetes - 当容器之一在完成其任务并终止时终止时,如何使 k8s 多容器 pod 状态准备就绪
- flutter - 让父母 onPressed 位于其孩子的 onPressed 之上
- javascript - Javascript 看不到从本地文件中提取的 html 元素
- c++ - 我需要整合我的 c++ 代码和 qml。但是我在使用 qmlRegisterType 时遇到了许多错误“未定义对‘Middlemen::staticMetaObject’的引用”
- c - Vulkan 和结构成员对齐
- java - 如何访问同一接口的不同实现的不同属性
- tabulator - 如何检测制表器中内置“选择”编辑器的值更改事件?
- java - gradle 创建 jar 不适用于“实现”依赖项
- twitter-bootstrap - Twitter Bootstrap - 包装网格列问题
- amazon-web-services - Teradata 数据库连接问题