Kubernetes: Image pull policies

2 min read | by Jordi Prats

On Kubernetes we can configure using the Pod manifest under which conditions we want to query the container registry to pull images by using the imagePullPolicy setting. We can configure the it on several objects like Deployment, StatefulSet, Pod, Job... In fact, we can set it on any object that includes a Pod template

apiVersion: v1
kind: Pod
metadata:
  name: test-pod
  namespace: demo
spec:
  containers:
  - image: alpine
    imagePullPolicy: IfNotPresent
(...)

We can set it to the following 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