gpt4 book ai didi

docker - 我们如何在 Kubernetes 中查看缓存的图像?

转载 作者:行者123 更新时间:2023-12-02 12:01:42 26 4
gpt4 key购买 nike

我使用 kops 作为 kubernetes 部署。
我注意到,每当在部署文件中输入具有相同标签号的图像时,如果 imagepullpolicy,系统就会采用前一个图像。未设置为 always有什么方法可以在 kubernetes 环境中查看容器的所有缓存图像?
就像假设我有一张图片 test:56当前在部署中运行,test:1test:55以前使用过,那么 kubernetes 是否缓存这些图像?如果是的话在哪里可以找到?

最佳答案

  • 对您的环境的评论:

    I noticed that whenever an image with same tag number is entered in deployment file the system takes the previous image if imagepullpolicy is not set to always


  • 一个 pre-pulled image可用于预加载某些图像以提高速度或作为对私有(private)注册表进行身份验证的替代方法,从而优化性能。

    docker 将始终缓存本地使用的所有图像。

    由于您使用的是 EKS,请记住,如果您有节点运行状况管理(意味着如果节点发生故障将被替换),新节点将不会从旧节点缓存图像,因此存储您的图像总是一个好主意像 your Cloud Provider Registry 这样的注册表上的图像或本地注册表。
  • 让我们解决您的第一个问题:

    Is there any way in which I can see all the cached images of a container in kubernetes environment ?


  • 是的,您必须使用 docker images列出存储在您的环境中的图像。
  • 第二个问题:

    Like suppose I have an image test:56 currently running in a deployment and test:1 to test:55 were used previously, so does Kubernetes cache those images ? and if yes where can those be found ?


  • 我为你准备了一个例子:
  • 我根据官方的busybox镜像部署了几个pod:
  • $ kubectl run busy284 --generator=run-pod/v1 --image=busybox:1.28.4
    pod/busy284 created
    $ kubectl run busy293 --generator=run-pod/v1 --image=busybox:1.29.3
    pod/busy284 created
    $ kubectl run busy284 --generator=run-pod/v1 --image=busybox:1.28
    pod/busy28 created
    $ kubectl run busy284 --generator=run-pod/v1 --image=busybox:1.29
    pod/busy29 created
    $ kubectl run busy284 --generator=run-pod/v1 --image=busybox:1.30
    pod/busy284 created
    $ kubectl run busybox --generator=run-pod/v1 --image=busybox
    pod/busybox created

    现在让我们检查存储在 docker images 中的图像
    $ docker images
    REPOSITORY TAG IMAGE ID CREATED SIZE
    k8s.gcr.io/kube-proxy v1.17.3 ae853e93800d 5 weeks ago 116MB
    k8s.gcr.io/kube-controller-manager v1.17.3 b0f1517c1f4b 5 weeks ago 161MB
    k8s.gcr.io/kube-apiserver v1.17.3 90d27391b780 5 weeks ago 171MB
    k8s.gcr.io/kube-scheduler v1.17.3 d109c0821a2b 5 weeks ago 94.4MB
    kubernetesui/dashboard v2.0.0-beta8 eb51a3597525 3 months ago 90.8MB
    k8s.gcr.io/coredns 1.6.5 70f311871ae1 4 months ago 41.6MB
    k8s.gcr.io/etcd 3.4.3-0 303ce5db0e90 4 months ago 288MB
    kubernetesui/metrics-scraper v1.0.2 3b08661dc379 4 months ago 40.1MB
    busybox latest 83aa35aa1c79 10 days ago 1.22MB
    busybox 1.30 64f5d945efcc 10 months ago 1.2MB
    busybox 1.29 758ec7f3a1ee 15 months ago 1.15MB
    busybox 1.29.3 758ec7f3a1ee 15 months ago 1.15MB
    busybox 1.28 8c811b4aec35 22 months ago 1.15MB
    busybox 1.28.4 8c811b4aec35 22 months ago 1.15MB

    您可以看到列出的所有推送的图像。

    最好使用命令 docker system prune 从系统中清除旧资源。不时释放服务器上的空间。

    如果您有任何疑问,请在评论中告诉我。

    关于docker - 我们如何在 Kubernetes 中查看缓存的图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60774740/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com