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

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

kubectl set image RESOURCE/NAME CONTAINER=IMAGE [...]

Parameters

ParameterDescription
CONTAINER=IMAGE Container name and new image; repeat for several containers.

Examples

Change an image
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.

The container name must match
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).

Was this page helpful?