Kubectl Essentials
Day-to-day kubectl commands for cluster objects. Results appear in the same fence: same-line # comments when short, multiline # blocks below the sample when not. Fences are bash, dockerfile, or yaml as appropriate.
Search across all documentation pages
Day-to-day kubectl commands for cluster objects. Results appear in the same fence: same-line # comments when short, multiline # blocks below the sample when not. Fences are bash, dockerfile, or yaml as appropriate.
Create or update from manifest.
kubectl apply -f deploy.yaml
# deployment.apps/api configuredList resources.
kubectl get pods -o wide
# NAME READY STATUS IP NODEContainer logs.
kubectl logs deploy/api -c api --tail=100 -f
# follow last 100 linesShell into a pod.
kubectl exec -it deploy/api -- sh
# interactive shellWatch or undo Deployments.
kubectl rollout status deploy/api
# deployment "api" successfully rolled out
kubectl rollout undo deploy/api
# rolled backEvents and details.
kubectl describe pod web-xyz
# Events: ...Delete by file or name.
kubectl delete -f deploy.yaml
# deployment.apps "api" deletedContexts and clusters.
kubectl config get-contexts
# CURRENT NAME CLUSTER AUTHINFOLocal port to pod/service.
kubectl port-forward svc/api 8080:80
# Forwarding from 127.0.0.1:8080 -> 80Server-side dry diff before apply.
kubectl diff -f deploy.yaml
# shows PATCH differencesWait for condition.
kubectl wait --for=condition=available deploy/api --timeout=120s
# deployment.apps/api condition metMetrics (metrics-server required).
kubectl top pods
# NAME CPU MEMFilter with -l.
kubectl get pods -l app=api
# pods matching labelExtract fields.
kubectl get deploy api -o jsonpath='{.status.readyReplicas}{"\n"}'
# 3Validate without persist.
kubectl apply -f deploy.yaml --dry-run=client -o yaml
# prints object onlyStack versions: Kubernetes 1.36.2 · Docker Engine 29.6.1 · Helm 3 · Compose v2 · containerd via CRI
Reviewed by Chris St. John·Last updated Jul 18, 2026