DEV Community

John  Ajera
John Ajera

Posted on

Top 20 kubectl Commands for Everyday Kubernetes Workflows

🚀 Top 20 Most Useful kubectl Commands for Everyday Kubernetes Workflows

Whether you're a developer, SRE, DevOps engineer, or just starting out with Kubernetes, mastering kubectl is essential. Here’s a curated list of the top 20 kubectl commands that are universally useful across teams and cloud platforms (EKS, GKE, AKS, etc.). These commands will save you time, reduce confusion, and help you debug faster.


🔟 Most Commonly Used kubectl Commands

1. Get all pods across namespaces

kubectl get pods -A
Enter fullscreen mode Exit fullscreen mode

Great for seeing what’s running cluster-wide and spotting stuck or crashing pods.


2. Describe a pod (deep debugging)

kubectl describe pod <pod-name> -n <namespace>
Enter fullscreen mode Exit fullscreen mode

Reveals node assignment, events, taints, failed mounts, and more.


3. View logs from a pod

kubectl logs <pod-name> -n <namespace>
Enter fullscreen mode Exit fullscreen mode

Use --previous if the pod has crashed and restarted.


4. Exec into a running container

kubectl exec -it <pod-name> -n <namespace> -- /bin/sh
Enter fullscreen mode Exit fullscreen mode

Great for real-time inspection, testing configs, or quick troubleshooting.


5. View recent events (cluster-wide)

kubectl get events -A --sort-by='.lastTimestamp'
Enter fullscreen mode Exit fullscreen mode

Use this to see the latest cluster activity, scheduling failures, crashes, and warnings.


6. View resource usage per pod

kubectl top pods -A
Enter fullscreen mode Exit fullscreen mode

Requires Metrics Server installed. Useful for performance monitoring.


7. Get all services across namespaces

kubectl get svc -A
Enter fullscreen mode Exit fullscreen mode

Quickly see which services are exposed and their types (ClusterIP, LoadBalancer, etc).


8. Restart a deployment

kubectl rollout restart deployment <name> -n <namespace>
Enter fullscreen mode Exit fullscreen mode

Triggers a rolling restart—useful after changing ConfigMaps, Secrets, or images.


9. Port forward to a service or pod

kubectl port-forward svc/<svc-name> 8080:80 -n <namespace>
Enter fullscreen mode Exit fullscreen mode

Perfect for accessing internal services locally.


10. Get everything in a namespace

kubectl get all -n <namespace>
Enter fullscreen mode Exit fullscreen mode

One-liner to view pods, deployments, services, etc., all at once.


🔟 More Essential kubectl Commands

11. Check node info

kubectl get nodes -o wide
Enter fullscreen mode Exit fullscreen mode

Displays node capacity, labels, roles, and IPs.


12. List namespaces with labels

kubectl get namespaces --show-labels
Enter fullscreen mode Exit fullscreen mode

Helps with namespace-level Fargate profiles and label selectors.


13. Get custom resources (CRDs)

kubectl get crds
Enter fullscreen mode Exit fullscreen mode

Essential when working with operators, controllers, or observability tooling.


14. Copy files into/from a pod

kubectl cp ./local-file.txt <pod-name>:/tmp/ -n <namespace>
Enter fullscreen mode Exit fullscreen mode

Use this for backups, config injection, or pulling logs/artifacts out.


15. Apply a manifest

kubectl apply -f your-file.yaml
Enter fullscreen mode Exit fullscreen mode

Declarative way to manage resources.


16. Delete a resource

kubectl delete deployment <name> -n <namespace>
Enter fullscreen mode Exit fullscreen mode

Useful for clearing broken resources blocking Terraform or Helm.


17. Watch pod status live

kubectl get pods -n <namespace> -w
Enter fullscreen mode Exit fullscreen mode

Great for seeing rollout or crash cycles in real time.


18. Label a resource

kubectl label pod <pod-name> env=staging -n <namespace>
Enter fullscreen mode Exit fullscreen mode

Labels are powerful for selectors, policies, and organizing workloads.


19. Taint a node

kubectl taint nodes <node-name> key=value:NoSchedule
Enter fullscreen mode Exit fullscreen mode

Advanced scheduling control—combine with pod tolerations.


20. Explain a Kubernetes resource

kubectl explain deployment.spec.template.spec.containers
Enter fullscreen mode Exit fullscreen mode

Learn the structure of complex manifests right from the CLI.


✅ Wrap-up

Mastering these 20 kubectl commands will level up your day-to-day efficiency in any Kubernetes environment—especially when using infrastructure as code with Terraform or Helm. Keep this cheat sheet close, and you'll debug faster and deploy smarter.

Feel free to bookmark or share! 🚀

Top comments (1)

Collapse
 
armando_lopez_a4f2645442c profile image
Armando Lopez •

Very useful. thank you.