【发布时间】: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的输出是什么?你是如何决定它使用旧图像的? -
...但我见过的最佳实践是给每个构建一个唯一的标签(也许让您的 CI 系统标签构建带有提交 ID 或日期戳);那么这不是问题,而且如果构建不起作用,您可以轻松回滚。
-
您使用的是本地环境还是本地环境?什么K8s版本?
-
@Shashank V ,我发现 45f6b42ab2f76 是摘要,49889fd96652 是图像ID。所以也许它更新成功了。
标签: kubernetes