Kubectl Commands Masterclass
Essential CLI commands to inspect, debug, manage, and execute commands across your Kubernetes cluster.
1. Core Kubectl Commands Cheat Sheet
| Command | Description | Usage Example |
|---|---|---|
kubectl get | Lists resources (pods, svc, deploy, ns) | kubectl get pods -o wide |
kubectl describe | Shows detailed resource state & event logs | kubectl describe pod my-pod |
kubectl apply -f | Applies declarative configuration file(s) | kubectl apply -f deployment.yaml |
kubectl delete | Deletes resource(s) from cluster | kubectl delete pod my-pod |
kubectl logs | Fetches pod console stdout logs | kubectl logs -f my-pod -c container-1 |
kubectl exec | Executes interactive shell in container | kubectl exec -it my-pod -- bash |
kubectl port-forward | Forwards local port to cluster pod/service | kubectl port-forward svc/my-svc 8080:80 |
2. Live Debugging Workflows
A. Forwarding Cluster Service to Local Machine:
kubectl port-forward service/postgres-service 5432:5432
B. Opening Interactive Shell Inside Pod:
kubectl exec -it my-app-pod -n production -- /bin/sh
Next Up
Explore Pods: Pod lifecycle, container specs, and multi-container patterns (Sidecar pattern).
Next Lesson: Pods Basics & Patterns →