Most day-to-day cluster work relies on a small set of kubectl commands. This reference groups them by task, from cluster info to debugging, and every command works the same on minikube, a kubeadm cluster or Amazon EKS. The earlier parts of this series explain the objects behind them, and the official kubectl reference lists every command.
Command Use kubectl version Show client and server versions kubectl cluster-info Show the control plane and core service addresses kubectl get nodes List nodes kubectl describe node <node-name> Detailed node information kubectl top nodes Node CPU and memory use (needs metrics-server)
Command Use kubectl get namespaces List namespaces kubectl create namespace dev Create a namespace kubectl delete namespace dev Delete a namespace and everything in it kubectl config set-context --current --namespace=dev Make dev the default namespace
Command Use kubectl run mynginx --image=nginx --port=80 Start a single pod kubectl get pods List pods kubectl get pods -o wide List pods with node and IP kubectl describe pod <pod> Detailed pod info and events kubectl logs <pod> Show logs kubectl logs <pod> -c <container> Logs of one container in the pod kubectl exec -it <pod> -- /bin/bash Open a shell in the container kubectl port-forward <pod> 8080:80 Forward local port 8080 to port 80 in the pod kubectl delete pod <pod> Delete a pod
Command Use kubectl get deployments List Deployments kubectl create deployment nginx --image=nginx Create a Deployment kubectl describe deployment <name> Deployment details kubectl scale deployment nginx --replicas=5 Scale a Deployment kubectl set image deployment/nginx nginx=nginx:1.27 Update the container image kubectl rollout status deployment/nginx Watch a rollout kubectl rollout history deployment/nginx Show rollout history kubectl rollout undo deployment/nginx Roll back to the previous revision kubectl rollout restart deployment/nginx Restart all pods with a rolling update
Command Use kubectl get svc List Services kubectl expose deployment nginx --type=NodePort --port=80 Create a Service for a Deployment kubectl describe svc <name> Service details, including endpoints kubectl delete svc <name> Delete a Service
Command Use kubectl create configmap mycfg --from-literal=ENV=prod Create from a key-value pair kubectl create configmap mycfg --from-file=app.conf Create from a file kubectl get configmaps List ConfigMaps kubectl describe configmap mycfg Show keys and values kubectl delete configmap mycfg Delete a ConfigMap
Command Use kubectl create secret generic mysecret --from-literal=password=<value> Create a Secret kubectl get secrets List Secrets kubectl describe secret mysecret Show keys and sizes, not values kubectl get secret mysecret -o yaml Show the base64-encoded values kubectl delete secret mysecret Delete a Secret
Secret values are only base64-encoded, not encrypted. To read one value:
terminal
$ kubectl get secret mysecret -o jsonpath = '{.data.password}' | base64 --decode Copy command
Warning
A password typed in a --from-literal command is saved in your shell history. For real secrets, use --from-file or a secrets manager.
Command Use kubectl get ingress List Ingress objects kubectl describe ingress <name> Ingress rules and backends kubectl delete ingress <name> Delete an Ingress
Command Use kubectl get jobs List Jobs kubectl create job testjob --image=busybox -- echo "Hi" Create a one-off Job kubectl get cronjobs List CronJobs kubectl delete job <name> Delete a Job kubectl delete cronjob <name> Delete a CronJob
Command Use kubectl get pv List PersistentVolumes kubectl get pvc List PersistentVolumeClaims kubectl describe pv <name> PersistentVolume details kubectl describe pvc <name> Claim details and binding status kubectl delete pvc <name> Delete a claim
Command Use kubectl edit deployment nginx Edit a live resource in your editor kubectl edit svc myservice Edit a live Service
Live edits are not saved in your YAML files. Use them only for quick tests.
Command Use kubectl apply -f app.yaml Create or update the resources in a file kubectl apply -f k8s/ Apply every manifest in a folder kubectl diff -f app.yaml Show what would change before applying kubectl delete -f app.yaml Delete the resources in a file
Command Use kubectl get pods -o wide Extra columns kubectl get pods -o yaml Full YAML output kubectl get pods -o json Full JSON output kubectl get pods --sort-by=.metadata.name Sort by a field kubectl get pods -A All namespaces
Command Use kubectl describe <resource> <name> Status and events for any object kubectl get events --sort-by=.metadata.creationTimestamp Event timeline kubectl logs <pod> --previous Logs of the last crashed container kubectl exec -it <pod> -- sh Shell into a pod that has no bash kubectl debug node/<node> -it --image=busybox Start a debug pod on a node
Command Use kubectl config get-contexts List contexts kubectl config use-context <context> Switch cluster kubectl config current-context Show the current context kubectl config view Show the kubeconfig kubectl config set-context <context> --namespace=<ns> Change a context's settings
Command Use kubectl label pod <pod> env=prod Add a label kubectl label pod <pod> env- Remove a label kubectl get pods -l env=prod Filter by label kubectl annotate pod <pod> description="My pod" Add an annotation
Command Use kubectl delete pod <pod> Delete a pod kubectl delete deployment <name> Delete a Deployment and its pods kubectl delete namespace <name> Delete a namespace and everything in it kubectl delete pods --all Delete all pods in the current namespace
Generate the first draft of a manifest with kubectl instead of writing it from memory:
terminal
$ kubectl create deployment nginx --image = nginx --dry-run = client -o yaml > deployment.yaml
$ kubectl create configmap test --from-literal = a = 1 --dry-run = client -o yaml Copy 2 commands
--dry-run=client builds the object without sending it to the cluster.
Short name Resource po pods svc services deploy deployments rs replicasets cm configmaps ns namespaces pv / pvc persistentvolumes / persistentvolumeclaims
For example, kubectl get po is the same as kubectl get pods . kubectl api-resources lists every short name.
get , describe , logs and exec solve most day-to-day questions.
Use apply -f with files in Git. Keep edit , scale and set image for quick tests.
kubectl get events and describe show why a resource is failing, not only that it is failing.
--dry-run=client -o yaml is the fastest way to start a new manifest.
Contexts let one kubectl switch between minikube, kubeadm and EKS clusters.