setting image pull policy using kubectl
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
imagePullPolicy controls when Kubernetes pulls a container image from the registry. It is a small field in the pod template, but it affects rollout behavior, registry traffic, and whether a node reuses a cached image. The important operational point is that you do not usually change it with kubectl set image; you change it by editing or patching the workload spec.
Understand the Available Policies
Kubernetes supports three pull policies:
- '
Always: pull the image every time the container starts.' - '
IfNotPresent: pull only when the image is not already cached on the node.' - '
Never: never pull from a registry; the image must already exist on the node.'
If you omit the field, Kubernetes applies defaults based on the image reference. For example, :latest defaults to Always, while a specific tag usually defaults to IfNotPresent. Relying on those defaults is possible, but explicit configuration is easier to review and less surprising during incident work.
Set the Policy in the Manifest
The cleanest way to manage imagePullPolicy is in the YAML that defines the workload.
Apply it with:
This is the most maintainable path because the desired state remains in version control. If the cluster is recreated or another engineer rolls the deployment later, the pull policy stays consistent.
Patch an Existing Deployment
If the workload already exists and you need to change the pull policy from the terminal, patch the pod template on the controller object.
That updates the deployment template, which causes Kubernetes to create a new ReplicaSet and roll new pods. You are not mutating a running pod in place; you are changing the template from which future pods are created.
Verify the change with a jsonpath query:
You can also inspect the rollout:
Why kubectl set image Is Not Enough
kubectl set image updates the image field, not the pull policy field.
That command is useful when you want a different image tag, but it does not answer the question of when the node should re-pull the image. If your operational goal is "always fetch from the registry" or "reuse cached images on the node," you must set imagePullPolicy explicitly in the template.
This distinction matters most when teams publish mutable tags. For example, if someone keeps pushing new bytes to the same tag, IfNotPresent may keep running the cached version, while Always forces a fresh pull on restart. That is one reason immutable version tags are the safer production pattern.
Choose a Sensible Policy
A simple rule works well in most environments:
- Use
IfNotPresentwith immutable version tags in production. - Use
Alwaysin development only when you truly rely on mutable tags. - Use
Neveronly in specialized environments where images are preloaded onto every node.
For example, if a CI pipeline publishes myapp:2026-03-07.1, this spec is predictable and efficient:
The node can reuse the cached image, and the tag itself identifies the exact build.
Common Pitfalls
- Assuming
kubectl set imagecan changeimagePullPolicy. - Using
:latestin production and then being surprised by inconsistent rollouts. - Expecting existing running pods to change behavior without a rollout.
- Setting
Neveron nodes that do not already contain the image. - Relying on implicit defaults instead of writing the policy into the manifest.
Summary
- '
imagePullPolicybelongs in the pod template.' - The most maintainable approach is to declare it in YAML and apply the manifest.
- For an existing deployment, use
kubectl patchon the deployment template. - '
kubectl set imagechanges the image reference, not the pull policy.' - In production, pair immutable tags with an explicit
IfNotPresentorAlwayspolicy based on your rollout model.
Related reading
- Setting up Kubernetes on NixOS
- Setup Kubernetes Pods via API Call using Go and Operator SDK
- Setup securityContext inside kubernetes deployment
- Share persistent volume claims amongst containers in Kubernetes/OpenShift
- Setting up MySQL and importing dump within Dockerfile
- sh 1 react-scripts not found In Docker
- Setting queueSize parameter for ch.qos.logback.classic.AsyncAppender
- Setting secrets as environment variables in deployment file

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.