Skip to content
LatchkeyLatchkey home

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

Terminal
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=512Mi

Common 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.

Using this in CI

A runner has no kubeconfig, no cached context, and no interactive auth. Every kubectl invocation in CI needs the context supplied explicitly, and most confusing CI failures here are the command running against the wrong cluster or no cluster at all.

Terminal
# never rely on the ambient context on a runner
kubectl --context "$KUBE_CONTEXT" -n "$NAMESPACE" get pods

# confirm what you are actually connected to before mutating anything
kubectl config current-context
kubectl cluster-info

# fail fast instead of hanging on an unreachable API server
kubectl --request-timeout=30s get nodes

Frequently asked questions

kubectl set: Usage, Options & Common CI Errors?
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 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.

Related guides

References

Run this faster and cheaper on Latchkey managed runners - self-healing included. Start free → 30-day trial · No credit card