kubectl set: Usage, Options & Common CI Errors
Patch a specific field - image, env, or resources - without editing YAML.
kubectl set changes one well-known field on a live resource. kubectl set image is the canonical CI deploy step: promote a Deployment to a freshly built image tag in a single command.
What it does
kubectl set image deploy/web container=image:tag updates a container's image, which triggers a new rollout. set env adds, changes, or removes environment variables; set resources patches CPU/memory requests and limits; set serviceaccount and set selector cover other common fields. Each one is a targeted, scriptable mutation.
Common usage
kubectl set image deploy/web web=myreg/web:${GIT_SHA}
kubectl set env deploy/web LOG_LEVEL=debug
kubectl set env deploy/web --from=configmap/app-cfg
kubectl set resources deploy/web -c=web --limits=cpu=500m,memory=512MiCommon errors in CI
"error: unable to find container named \"X\"" means the container name in your set image command does not match the Deployment's container name - list it with kubectl get deploy/web -o jsonpath='{.spec.template.spec.containers[*].name}'. A subtle CI bug: set image with a tag that did not actually change (e.g. :latest re-pushed) updates the spec identically, so Kubernetes sees no diff and does not roll out the new image - pin to an immutable tag like the commit SHA so each deploy is a real change. Follow set with kubectl rollout status to gate on the result.