Kubernetes Commands: Basic -> Intermediate -> Advanced
1. Basic Commands (For Starters / Day-to-Day Operations)
- kubectl version --short: Check client & server version
- kubectl cluster-info: Show cluster details
- kubectl get nodes: List all nodes in the cluster
- kubectl get pods: List pods in default namespace
- kubectl get pods -A: List pods across all namespaces
- kubectl describe pod <pod_name>: Detailed info about a pod
- kubectl logs <pod_name>: View logs of a pod
- kubectl exec -it <pod_name> -- bash: Open interactive shell inside pod
- kubectl create -f <file>.yaml: Create resource from YAML file
- kubectl delete pod <pod_name>: Delete a pod
2. Intermediate Commands (For Developers & CI/CD)
- kubectl get deployments: List deployments
- kubectl create deployment <name> --image=<img>: Quick deployment
- kubectl expose deployment <name> --type=NodePort --port=80: Expose deployment as service
- kubectl get svc: List services
- kubectl scale deployment <name> --replicas=3: Scale deployment pods
- kubectl rollout status deployment/<name>: Check rollout status
- kubectl rollout undo deployment/<name>: Rollback deployment
- kubectl config view: View kubeconfig file
- kubectl config use-context <cluster>: Switch context between clusters
- kubectl get namespaces: List namespaces
- kubectl create namespace dev: Create namespace
- kubectl get pods -n <namespace>: Get pods from a namespace
3. Advanced Commands (For DevOps / Production / Troubleshooting)
- kubectl top pod: Show pod resource usage (CPU/Memory)
- kubectl top node: Show node resource usage
- kubectl get events: List cluster events (for debugging)
- kubectl drain <node>: Safely evict pods before maintenance
- kubectl cordon <node>: Mark node unschedulable
- kubectl uncordon <node>: Mark node schedulable again
- kubectl taint nodes <node> key=value:NoSchedule: Prevent pods from scheduling on node
- kubectl apply -f <file>.yaml: Update config without deleting
- kubectl edit deployment <name>: Edit live deployment
- kubectl port-forward pod/<pod> 8080:80: Access pod locally
- kubectl api-resources: Show all available resource types
- kubectl get all -n <namespace>: Show all resources in namespace
- kubectl debug: Start ephemeral container for debugging