Where k8s images be cached when use helm

79 Views Asked by At

Hi i have a question about how helm and k8s handle caching docker images?

I want to know this because i use helmfile to managing releases and we run helmfile on gitlab runner. I want to somehow cache the images to help the pipline be faster. But i don’t know excatly which part is for caching the images? I must cache where the helm command run or this config should be set on k8s?

2

There are 2 best solutions below

0
Ali Kang On

Images are not cached in any centralized location, they must be present on any node that the pods are going to be deployed (since you do not know which nodes are going to host the pods (unless you use affinity/antiaffinity or special annotations) separately. But if the imagepullpolicy is set to "if not present"; it would check to see if that particular image (with the same hash) is already present or not. so in short, the images are not cached any where but could be already present on nodes (separately)

0
David Maze On

Neither Helm nor Helmfile cache or even download the images. They just pass an image: reference in Kubernetes YAML into the cluster.

Once you've submitted the YAML (via helmfile apply for example), and the cluster has created Pods from your Deployment, and the Pods are scheduled on a node, then each node will take responsibility for downloading the image. They are "cached" there, in the sense that if another Pod starts up with the same image: then the existing image will be reused. But there are no management tools for this – you can't preload or manually evict images – and you can't generally predict which node will be running the Pod and will need a copy of the image.

A combination of best practices here would be to use a distinct tag for each image build, make sure to use a Deployment and not bare Pods, and not try to directly manipulate the Nodes. When you update your Deployment spec, the Node will need to download the image, and it will take a little time, but the old Pods will keep running until the new Pods are functional.