kubectl-set
Update specific fields of Kubernetes resources
TLDR
Update the image of a container in a deployment
Update the image of all containers in a deployment
Set resource limits (CPU and memory) on a deployment
Set an environment variable on a deployment
Remove an environment variable from a deployment
Import environment variables from a secret or ConfigMap
Update the service account of a deployment
SYNOPSIS
kubectl set SUBCOMMAND [NAME] resources [--container=<name>] [--dry-run=<strategy>] [--local] [--record] [--resource-version=<version>] [--timeout=<duration>]
PARAMETERS
env
Update environment variables on a pod or pod template
image
Update container image(s) for a pod template or container
resources
Update resource requests/limits on pod template containers
serviceaccount
Update serviceAccount on a resource
subject
Update subjects in RBAC RoleBinding/ClusterRoleBinding
selector
Set selector on a resource
trigger
Update triggers on ReplicationController
--container
Container name; if omitted, selects all
--dry-run
"client|server|none"; preview without applying
--local
Client-side update; output to stdout
--record
Record current kubectl command in resource annotations
--resource-version
Precondition resource version
--timeout
Timeout for server-side operations
DESCRIPTION
kubectl set is a powerful subcommand of the Kubernetes CLI tool kubectl designed to update specific fields on resources like deployments, pods, and replica sets without a full replacement or restart. It supports targeted modifications via subcommands such as image, env, resources, enabling quick changes like updating container images, environment variables, or CPU/memory limits.
For instance, to bump a deployment's container image: kubectl set image deployment/myapp nginx=nginx:1.16. This triggers a rolling update with minimal disruption. It leverages strategic merge patches, preserving unspecified fields, and integrates with selectors for bulk operations.
Ideal for CI/CD pipelines and production tweaks, it requires appropriate RBAC permissions. Changes can be previewed with --dry-run, recorded for rollbacks via --record, and scoped to namespaces. Unlike kubectl patch, it's declarative for common fields but limited to supported subcommands.
Enhances declarative configs by bridging imperious updates, reducing kubectl apply cycles in dynamic clusters.
CAVEATS
Limited to specific fields/subcommands; uses strategic merge patch which may not support custom resources. Requires write permissions; not for complex JSON patches (use kubectl patch). Rolling updates may cause brief unavailability.
EXAMPLES
kubectl set image deployment/nginx nginx=nginx:1.16.1 --record
kubectl set env deployment/myapp DB_HOST=prod-db --containers=app
kubectl set resources deployment/myapp -c=app --requests=cpu=100m,memory=128Mi --limits=cpu=200m
SELECTORS
Use -l app=myapp for label-based resource selection, e.g., kubectl set image deployments -l app=myapp nginx=latest
HISTORY
Introduced in Kubernetes v1.11 (2017) as a convenience wrapper over patches. Subcommands expanded through v1.20+; now stable for core workloads. Developed by Kubernetes SIG-CLI for streamlined resource management.


