imagePullPolicy decides whether the kubelet asks the registry about an image before it starts a container. It has three values, a default that depends on the tag, and one rule that surprises people: the default is set once, when the object is created.
The three values
| Value | What the kubelet does |
|---|---|
IfNotPresent | Pulls only when the image is not already on the node. A node that has the tag keeps using what it has. |
Always | Asks the registry what the tag points to every time it starts a container. If the node already has that exact digest, nothing is downloaded; only the lookup happens. |
Never | Never pulls. The image must already be on the node, or the container fails with ErrImageNeverPull. |
The default, and why :latest changes it
Leave imagePullPolicy out and Kubernetes picks one when the object is created:
- the tag is
:latest, or there is no tag at all:Always; - any other tag, or a digest:
IfNotPresent.
The value is written into the object then, and it does not change if you later change the image. A Deployment created with :latest and moved to :1.4.2 keeps Always; one created with :1.4.2 and moved to :latest keeps IfNotPresent, and nodes that already have an old :latest go on running it. Set the field explicitly and this stops mattering.
The trap: a tag that moves
With IfNotPresent, a tag that is pushed again (:latest, :staging, :main) means different nodes run different images under the same name: the ones that pulled before the push keep the old one. Nothing fails, which is why it takes a while to notice. Two ways out:
- Deploy by digest.
image: registry.example.com/shop/checkout@sha256:…names exactly one image. Every node runs the same bytes, andIfNotPresentis safe. - Tags that never move. A release tag such as
v1.4.2pushed once and never again behaves like a digest. Many registries can enforce it.
What Always costs
Always does not mean downloading the image every time, but it does mean the registry must answer every time a container starts. If the registry is unreachable, or the credentials expired, pods cannot start, even on a node that has the image cached. For a busy cluster it also means a lookup per container start against the registry’s rate limits. Use it for tags you deliberately move, and pin everything else.
To make a running Deployment pick up a moved tag under Always, start new pods:
kubectl rollout restart deployment/checkout -n shop
Under IfNotPresent that does nothing for nodes that already have the tag, which is the clearest argument for digests.
Cluster-wide: the AlwaysPullImages admission controller
In a cluster shared by teams, a pod could start from an image another team pulled onto the node with their credentials. The AlwaysPullImages admission controller sets every new pod to Always, so each pod has to present its own credentials to the registry. It trades that isolation for a dependency on the registry at every start.
With a Subnomic registry
Repositories can carry immutable-tag rules, for example v*: a matching tag is pushed once, and moving, deleting or pruning it is refused. With that rule on your release tags, IfNotPresent runs the same image on every node, and a retention rule can clean up everything else without touching what production runs. Give the cluster a pull-only robot for its pull secret. When a pull fails anyway, ImagePullBackOff: why Kubernetes cannot pull the image reads the error for you.