Mastering Kubernetes: Essential kubectl Commands Every Developer Should Know

Abhiraj GhoshAbhiraj Ghosh
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 namespace

  • Use -o yaml or -o json for raw output

  • Use --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

Abhiraj Ghosh
Abhiraj Ghosh