简体   繁体   English

如何在 kubernetes 中提取已经缓存的图像?

[英]How to repull image in kubernetes that is already cached?

I am using kubernetes cluster with 20 worker node.我正在使用具有 20 个工作节点的 kubernetes 集群。 I have set image pull policy as IfNotPresent to reduce creation time.我已将图像拉取策略设置为 IfNotPresent 以减少创建时间。 Image is hosted on dockerhub.图像托管在 dockerhub 上。

When i update the image in dockerhub i need to clear cache from all 20 worker nodes.当我在 dockerhub 中更新图像时,我需要清除所有 20 个工作节点的缓存。 Currently i am doing docker pull on all 20 worker nodes to update latest image.目前我正在做 docker 拉所有 20 个工作节点以更新最新图像。

Is there any kubernetes native solution or any other best industry solution to update image on all nodes?是否有任何 kubernetes 原生解决方案或任何其他最佳行业解决方案来更新所有节点上的图像?

the best industry solution is to use a unique tag for each deployed image.最好的行业解决方案是为每个部署的图像使用一个唯一的标签。 change the image tag and k8s will handle the upgrade for you.更改图像标签,k8s 将为您处理升级。 you only have this problem because you want to use the same tag even though the image changes.你只有这个问题,因为你想使用相同的标签,即使图像发生变化。 Whatever the reason you think it's not worth explicitly versioning your image, you're wrong:P.无论您认为不值得明确对图像进行版本控制的原因是什么,您都错了:P。 Explicit versions are well work the effort of specifying them显式版本很好地指定了它们

u need to use Always in ImagePullPolicy.你需要在 ImagePullPolicy 中使用 Always。 if so, whenever there is change in commit hash with a specific tag, K8S will pull again.如果是这样,只要提交 hash 有特定标签的更改,K8S 就会再次拉取。 Remember to set rollingUpdate too.记得也要设置 rollingUpdate。

It depends if you are versioning your image on Docker Hub.这取决于您是否在 Docker Hub 上对映像进行版本控制。

It's strongly encouraged to version your images for few reasons.出于几个原因,强烈建议您对图像进行版本控制。

  • it's quicker to rollback in case of an issue, because you just change version number to previous出现问题时回滚更快,因为您只需将版本号更改为以前的版本

  • all your pods will use the same version of the image您所有的 pod 都将使用相同版本的图像

You can read about configuration of Container Images in Kubernetes documentation.您可以在 Kubernetes 文档中阅读有关容器镜像配置的信息。

The imagePullPolicy and the tag of the image affect when the kubelet attempts to pull the specified image. imagePullPolicy和镜像的标签会影响kubelet尝试拉取指定镜像的时间。

  • imagePullPolicy: IfNotPresent : the image is pulled only if it is not already present locally. imagePullPolicy: IfNotPresent :仅当图像在本地不存在时才被拉取。

  • imagePullPolicy: Always : the image is pulled every time the pod is started. imagePullPolicy: Always :每次启动 Pod 时都会拉取镜像。

  • imagePullPolicy is omitted and either the image tag is :latest or it is omitted: Always is applied. imagePullPolicy被省略并且图像标签是:latest或者被省略: Always应用。

  • imagePullPolicy is omitted and the image tag is present but not :latest : IfNotPresent is applied. imagePullPolicy被省略并且图像标签存在但不存在:latest : IfNotPresent被应用。

  • imagePullPolicy: Never : the image is assumed to exist locally. imagePullPolicy: Never :假设图像存在于本地。 No attempt is made to pull the image.没有尝试拉取图像。

Note: To make sure the container always uses the same version of the image, you can specify its digest , for example sha256:45b23dee08af5e43a7fea6c4cf9c25ccf269ee113168c19722f87876677c5cb2 .注意:为确保容器始终使用相同版本的映像,您可以指定其摘要,例如sha256:45b23dee08af5e43a7fea6c4cf9c25ccf269ee113168c19722f87876677c5cb2 The digest uniquely identifies a specific version of the image, so it is never updated by Kubernetes unless you change the digest value.摘要唯一标识映像的特定版本,因此除非您更改摘要值,否则 Kubernetes 永远不会更新它。

Note: You should avoid using the :latest tag when deploying containers in production as it is harder to track which version of the image is running and more difficult to roll back properly.注意:在生产环境中部署容器时应避免使用:latest标签,因为很难跟踪哪个版本的镜像正在运行并且更难以正确回滚。

Note: The caching semantics of the underlying image provider make even imagePullPolicy: Always efficient.注意:底层图像提供程序的缓存语义甚至使imagePullPolicy: Always高效。 With Docker, for example, if the image already exists, the pull attempt is fast because all image layers are cached and no image download is needed.以 Docker 为例,如果镜像已经存在,那么拉取尝试很快,因为所有镜像层都被缓存,不需要下载镜像。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM