kubernetes: Image pull policies

2 min read

We can tell kubernetes under which conditions to query the container registry for images by using imagePullPolicy. We can configure the it on several objects like Deployment, StatefulSet, Pod, Job... actually, any object that includes a Pod template.

We can set it to several values:

  • IfNotPresent: the image is pulled only if it is not already present locally (this is de default value)
  • Always: Every time the image is needed it will query the image registry and compare it's hash with the locally cached (if present). It will attempt to download it only if the hash does not match
  • Never: the image must exist locally. It won't attempt to pull the image from the registry

There are a special cases when the imagePullPolicy is not defined:

  • If the image tag is :latest (or not defined), it will use the Always imagePullPolicy
  • If the image tag is present but not :latest, it will use the IfNotPresent imagePullPolicy

Posted on 05/05/2021