List all contexts; the asterisk marks the active cluster
kubectl config get-contextsHigh-frequency commands for contexts, inspection, logs, rollouts and node maintenance, with risk notes.
List all contexts; the asterisk marks the active cluster
kubectl config get-contextsSwitch context; later commands target that cluster
kubectl config use-context prodSet the default namespace of the current context
kubectl config set-context --current --namespace=<NS>Confirm which namespace is currently effective
kubectl config view --minify -o jsonpath='{..namespace}'Without it commands hit default; always pass -n across environments.
List all namespaces in the cluster
kubectl get nsList pods with node and IP columns
kubectl get pods -n <NS> -o wideShow the main resources of a namespace at once
kubectl get all -n <NS>Inspect events, images, mounts and probes of a pod
kubectl describe pod <POD> -n <NS>List events by time to spot scheduling or image pull errors
kubectl get events -n <NS> --sort-by=.lastTimestampDump full pod YAML for diffing or backup
kubectl get pod <POD> -n <NS> -o yamlFollow the last 100 log lines of a container
kubectl logs -f --tail=100 <POD> -n <NS> -c <CONTAINER>Pods with several containers require -c, otherwise it fails.
Show logs from the previous crash to debug restarts
kubectl logs <POD> -n <NS> --previousOpen a shell inside a container; slim images may lack bash
kubectl exec -it <POD> -n <NS> -- shForward a cluster service port to your local machine
kubectl port-forward svc/<SVC> 8080:80 -n <NS>Copy files between a pod and your local machine
kubectl cp <NS>/<POD>:/var/log/app.log ./app.logRequires tar inside the container, otherwise it fails.
Create a deployment quickly for validation
kubectl create deployment my-app --image=nginx:1.25 --replicas=2 -n <NS>Update the image and trigger a rolling update
kubectl set image deployment/my-app my-app=nginx:1.26 -n <NS>Watch the rollout progress until it completes
kubectl rollout status deployment/my-app -n <NS>Roll the pods again without changing the image tag
kubectl rollout restart deployment/my-app -n <NS>Roll back one revision; use --to-revision to pick one
kubectl rollout undo deployment/my-app -n <NS>Scale replicas; verify free node capacity first
kubectl scale deployment/my-app --replicas=4 -n <NS>Show pod memory usage sorted by consumption
kubectl top pod -n <NS> --sort-by=memoryInspect node allocation, taints and bound pods
kubectl describe node <NODE>Mark a node unschedulable while pods keep running
kubectl cordon <NODE>Evict all pods from a node; check replicas and PDBs first
kubectl drain <NODE> --ignore-daemonsets --delete-emptydir-dataSingle-replica services go down; run uncordon after maintenance.
Restore scheduling on the node
kubectl uncordon <NODE>Delete a pod to force recreation; safe only under a controller
kubectl delete pod <POD> -n <NS>Standalone pods deleted this way are gone for good.
Create a ConfigMap from a config file
kubectl create configmap app-config --from-file=app.conf -n <NS>Create a secret; the value stays in shell history
kubectl create secret generic app-secret --from-literal=password=<PASSWORD> -n <NS>Prefer --from-file or stdin to keep values out of history.
Create or update resources from a manifest
kubectl apply -f deployment.yaml -n <NS>Preview what apply would change
kubectl diff -f deployment.yaml -n <NS>Delete every resource in the manifest; diff before running
kubectl delete -f deployment.yaml -n <NS>Resources removed this way are hard to recover.
This website uses cookies to ensure you get the best experience on our website. Privacy Policy.