kubectl Deployments commands

32 commands in 4 groups: Manage, Scale, Rollout, List & Inspect. Click or tap any command to copy it. Official documentation: kubernetes.io.

Open in the interactive cheat sheet search, stars and every other section

Manage

Apply manifests, create and modify Deployments imperatively, and remove them from the cluster.
kubectl apply -f <directory>/
Apply all manifests in a directory
kubectl apply -f <file.yaml>
Apply a manifest from file
kubectl create deployment <name> --image=<image>
Create a Deployment imperatively
kubectl create deployment <name> --image=<image> --replicas=<n>
Create Deployment with replica count
kubectl delete deployment <name>
Delete a Deployment
kubectl delete -f <file.yaml>
Delete resources defined in file
kubectl delete deploy --all -n <namespace>
Delete all Deployments in Namespace
kubectl diff -f <file.yaml>
Preview changes before applying Deployment
kubectl edit deployment <name>
Edit Deployment in $EDITOR
kubectl patch deploy/<name> -p '{"spec":{"replicas":3}}'
Patch Deployment with JSON
kubectl set env deploy/<name> <KEY>=<VALUE>
Set or update environment variable
kubectl set image deploy/<name> <container>=<image>
Update container image
kubectl set resources deploy/<name> --limits=cpu=500m,memory=512Mi
Set resource limits on containers

Scale

Adjust replica count manually or automatically with a HorizontalPodAutoscaler.
kubectl autoscale deploy/<name> --min=2 --max=10 --cpu=80%
Create a HorizontalPodAutoscaler
kubectl delete hpa <name>
Delete a HorizontalPodAutoscaler
kubectl get hpa
List HorizontalPodAutoscalers
kubectl scale deploy/<name> --replicas=<n>
Scale Deployment to N replicas

Rollout

Track, pause, resume, and roll back Deployment updates across revisions.
kubectl annotate deploy/<name> kubernetes.io/change-cause="<message>"
Set change cause shown in rollout history
kubectl rollout history deploy/<name>
Show revision history
kubectl rollout pause deploy/<name>
Pause an in-progress rollout
kubectl rollout restart deploy/<name>
Trigger a rolling restart
kubectl rollout resume deploy/<name>
Resume a paused rollout
kubectl rollout status deploy/<name>
Watch rollout progress
kubectl rollout undo deploy/<name>
Roll back to the previous revision
kubectl rollout status deploy/<name> --timeout=<duration>
Wait for rollout with bounded timeout (CI-friendly)
kubectl rollout undo deploy/<name> --to-revision=<n>
Roll back to a specific revision
kubectl wait --for=condition=Available deployment/<name>
Wait until Deployment is Available

List & Inspect

View Deployments and their current state, replica count, and age.
kubectl describe deployment <name>
Full Deployment details and events
kubectl get deployments
List Deployments in current Namespace
kubectl get deploy -A
All Deployments across Namespaces
kubectl get deploy -n <namespace>
Deployments in a specific Namespace
kubectl get deployment <name> -o yaml
Get Deployment manifest as YAML