Kubernetes has become the de-facto orchestration platform for managing containerized applications at scale. Whether you’re deploying, scaling, or monitoring applications, mastering kubectl commands is essential for managing your Kubernetes clusters efficiently. Here, we explore the top 30 Kubernetes commands, complete with syntax and examples, that every developer and DevOps engineer should know.
1. kubectl get pods
Syntax: kubectl get pods
Example: Lists all pods in the current namespace
kubectl get pods
2. kubectl get nodes
Syntax: kubectl get nodes
Example: Lists all nodes in the cluster.
kubectl get nodes
3. kubectl get services
Syntax: kubectl get svc
Example: Lists all services in the namespace.
kubectl get svc
4. kubectl describe pod
Syntax: kubectl describe pod
Example: Provides detailed information about a pod.
kubectl describe pod my-pod
5. kubectl create
Syntax: kubectl create -f
Example: Creates resources from a YAML file.
kubectl create -f deployment.yaml
6. kubectl apply
Syntax: kubectl apply -f
Example: Updates resources defined in a YAML file.
kubectl apply -f deployment.yaml
7. kubectl delete
Syntax: kubectl delete -f
Example: Deletes the resources defined in the file.
kubectl delete -f deployment.yaml
8. kubectl logs
Syntax: kubectl logs
Example: Fetches the logs of a pod.
kubectl logs my-pod
9. kubectl exec
Syntax: kubectl exec -it --
Example: Executes a command in a running pod.
kubectl exec -it my-pod -- /bin/bash
10. kubectl scale
Syntax: kubectl scale --replicas= /
Example: Scales the number of replicas in a deployment.
kubectl scale --replicas=3 deployment/my-deployment
11. kubectl edit
Syntax: kubectl edit
Example: Allows inline editing of resources like deployments.
kubectl edit deployment my-deployment
12. kubectl port-forward
Syntax: kubectl port-forward :
Example: Forwards a local port to a pod’s port.
kubectl port-forward my-pod 8080:80
13. kubectl expose
Syntax: kubectl expose --port= --target-port=
Example: Exposes a resource as a new service.
kubectl expose deployment my-deployment --port=80 --target-port=8080
14. kubectl get configmaps
Syntax: kubectl get configmaps
Example: Lists all ConfigMaps in the namespace.
kubectl get configmaps
15. kubectl get secrets
Syntax: kubectl get secrets
Example: Lists all secrets.
kubectl get secrets
16. kubectl apply -k
Syntax: kubectl apply -k
Example: Applies resource configurations from a Kustomize directory.
kubectl apply -k ./my-kustomization/
17. kubectl cp
Syntax: kubectl cp :
Example: Copies files between a local machine and a pod.
kubectl cp ./file.txt my-pod:/tmp/
18. kubectl rollout status
Syntax: kubectl rollout status deployment/
Example: Monitors the status of a rollout.
kubectl rollout status deployment/my-deployment
19. kubectl rollout undo
Syntax: kubectl rollout undo deployment/
Example: Rolls back a deployment to a previous version.
kubectl rollout undo deployment/my-deployment
20. kubectl get events
Syntax: kubectl get events
Example: Lists recent cluster events.
kubectl get events
21. kubectl top pod
Syntax: kubectl top pod
Example: Shows resource usage of pods.
kubectl top pod
22. kubectl get namespaces
Syntax: kubectl get namespaces
Example: Lists all namespaces.
kubectl get namespaces
23. kubectl describe node
Syntax: kubectl describe node
Example: Provides detailed information about a node.
kubectl describe node my-node
24. kubectl delete pod
Syntax: kubectl delete pod
Example: Deletes a specific pod.
kubectl delete pod my-pod
25. kubectl get deployments
Syntax: kubectl get deployments
Example: Lists all deployments in the namespace.
kubectl get deployments
26. kubectl create namespace
Syntax: kubectl create namespace
Example: Creates a new namespace.
kubectl create namespace my-namespace
27. kubectl config use-context
Syntax: kubectl config use-context
Example: Switches to another context.
kubectl config use-context my-cluster
28. kubectl delete service
Syntax: kubectl delete service
Example: Deletes a specific service.
kubectl delete service my-service
29. kubectl get replicasets
Syntax: kubectl get rs
Example: Lists all ReplicaSets.
kubectl get rs
30. kubectl drain
Syntax: kubectl drain --ignore-daemonsets
Example: Safely drains a node for maintenance.
kubectl drain my-node --ignore-daemonsets
Explore more detailed content and step-by-step guides on our YouTube channel:-
Connect with Us!
Stay connected with us for the latest updates, tutorials, and exclusive content:
WhatsApp:- https://www.whatsapp.com/channel/0029VaeX6b73GJOuCyYRik0i
facebook:- https://www.facebook.com/S3CloudHub
youtube:- https://www.youtube.com/@s3cloudhub
github:- https://github.com/S3CloudHubRepo