kubectl 1.37 reference · Workloads
kubectl set image Command (kubectl)
Change the image of one or more containers in a workload's pod template, which starts a rolling update.
kubectl 1.37
Syntax
kubectl set image RESOURCE/NAME CONTAINER=IMAGE [...]
Parameters
| Parameter | Description |
|---|---|
CONTAINER=IMAGE |
Container name and new image; repeat for several containers. |
Examples
kubectl create namespace rc-ref-img > /dev/null
trap 'kubectl delete namespace rc-ref-img --wait=false > /dev/null' EXIT
kubectl -n rc-ref-img create deployment api --image=busybox:1.37 -- sleep 3600 > /dev/null
kubectl -n rc-ref-img set image deployment/api busybox=busybox:1.37-musl
kubectl -n rc-ref-img get deployment api -o jsonpath='{.spec.template.spec.containers[0].image}{"\n"}'
Output
deployment.apps/api image updated busybox:1.37-musl
Run this on your computer — see “Get Started” for setup.
kubectl create namespace rc-ref-img2 > /dev/null
trap 'kubectl delete namespace rc-ref-img2 --wait=false > /dev/null' EXIT
kubectl -n rc-ref-img2 create deployment api --image=busybox:1.37 -- sleep 3600 > /dev/null
kubectl -n rc-ref-img2 set image deployment/api wrong-name=busybox:1.37-musl 2>&1 | sed 's/^error: //' | cut -c1-60
Output
unable to find container named "wrong-name"
Run this on your computer — see “Get Started” for setup.
In GitOps setups, change the image in Git instead; a manual set image is overwritten (or reverted by self-heal).
Related
kubectl rollout· Manage Deployment, StatefulSet and DaemonSet rollouts: watch status, view history, restart and undo to a previous revision.- Rolling Updates and Rollbacks · tutorial