How can we see cached images in kubernetes?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
To effectively manage Kubernetes clusters, it is essential to understand how the system handles various components, including container images. Kubernetes utilizes container images stored in container registries to create and manage pods. Managing cached images is crucial for optimizing resource utilization and minimizing deployment times. This article delves into accessing, managing, and understanding cached images in a Kubernetes environment.
Cached Images in Kubernetes
Kubernetes nodes often cache container images to reduce the need to frequently download them from remote registries. This is both resource and time-efficient, especially when images are large or the network is slow or unreliable. Understanding where and how these cached images are stored, and accessing them effectively is important for Kubernetes administrators.
How Kubernetes Caches Images
When a `Pod` is scheduled onto a `Node`, the Kubernetes `kubelet` process checks whether the required container images are already available in the node’s image cache. If the image is not present, the `kubelet` retrieves it from the specified container registry. Once retrieved, the `kubelet` caches the image locally, which can lead to faster startup times for subsequent pods that use the same image.
Accessing Cached Images
To view cached images on a Kubernetes node, you need to access the node directly. The cached images are typically stored by the container runtime used. Kubernetes supports several container runtimes, such as Docker, `containerd`, and CRI-O. Each runtime has its own method of listing cached images.
Docker
If Docker is used as a container runtime, you can list cached images with:
- Docker:
- containerd:
- CRI-O:
- `imageGCHighThresholdPercent`: the threshold at which image garbage collection is triggered.
- `imageGCLowThresholdPercent`: once garbage collection is triggered, image space is reduced to this percentage.
- `evictionHard`: ensures that such conditions are met before triggering eviction.
- Always: always pull the image from the registry regardless of whether it’s already cached. This setting ensures you have the latest image but negates benefits from caching.
- IfNotPresent: use cached images if available, otherwise pull from the registry. This balances network usage and resource efficiency.
- Never: only use images that are cached and never pull from the registry. It requires the image to be manually cached or preloaded.
- Image Scanning: Regularly scan cached images for vulnerabilities using tools like Trivy, Clair, or others.
- Disk Space Monitoring: Implement alerting on nodes' disk space to preemptively manage space issues.
- Authentication: Secure access to nodes and container registries to prevent unauthorized image manipulations.

