Mastering Kubernetes: Essential kubectl Commands Every Developer Should Know

2 min read

๐งฑ Cluster Info
kubectl cluster-info
kubectl get nodes
kubectl describe node <node-name>
๐ฆ Deployments
kubectl create deployment nginx --image=nginx
kubectl apply -f deployment.yml
kubectl get deployments
kubectl describe deployment nginx
kubectl delete deployment nginx
๐ณ Pods
kubectl get pods
kubectl describe pod <pod-name>
kubectl logs <pod-name>
kubectl exec -it <pod-name> -- /bin/bash
kubectl delete pod <pod-name>
๐ Namespaces
kubectl get namespaces
kubectl create namespace my-namespace
kubectl delete namespace my-namespace
๐ Services
kubectl get svc
kubectl expose deployment nginx --port=80 --target-port=80 --type=NodePort
kubectl describe svc <service-name>
kubectl delete svc <service-name>
๐ Config & Resources
kubectl get all
kubectl get configmap
kubectl get secrets
kubectl describe configmap <config-name>
kubectl describe secret <secret-name>
๐ฅ Apply & Delete
kubectl apply -f <file>.yaml
kubectl delete -f <file>.yaml
๐งช Debugging & Logs
kubectl logs <pod-name>
kubectl logs -f <pod-name> # Follow logs
kubectl describe <resource> <name>
kubectl get events --sort-by='.metadata.creationTimestamp'
๐ Rollouts
kubectl rollout status deployment/nginx
kubectl rollout restart deployment/nginx
kubectl rollout undo deployment/nginx
๐งผ Cleanup
kubectl delete pod --all
kubectl delete deployment --all
kubectl delete svc --all
๐ Tips
Use
-n <namespace>
to specify namespaceUse
-o yaml
or-o json
for raw outputUse
--watch
to stream real-time updates
โ That's your essential kubectl cheat sheet!
What's your most-used kubectl command? Drop it in the comments!
#Kubernetes #kubectl #DevOps #CloudNative #ContainerOrchestration
0
Subscribe to my newsletter
Read articles from Abhiraj Ghosh directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
