Back to Cheat Sheets
Kubernetes (kubectl) Commands
Essential kubectl commands for managing Kubernetes clusters.
| Action | Command | Details |
|---|---|---|
| Get nodes | kubectl get nodes |
List all nodes in the cluster. |
| Get pods | kubectl get pods |
List all pods in the current namespace. |
| Describe pod | kubectl describe pod <pod-name> |
Show detailed info about a pod. |
| Create deployment | kubectl create deployment <name> --image=<image> |
Deploy a new application. |
| Scale deployment | kubectl scale deployment <name> --replicas=<num> |
Scale number of pod replicas. |
| Delete pod | kubectl delete pod <pod-name> |
Delete a specific pod. |
| Apply config | kubectl apply -f <file.yaml> |
Apply configuration from a file. |
| Get services | kubectl get svc |
List services in the namespace. |
| Expose deployment | kubectl expose deployment <name> --type=LoadBalancer --port=80 |
Create a service exposing deployment. |
| Logs | kubectl logs <pod-name> |
View logs of a pod. |
| Exec into pod | kubectl exec -it <pod-name> -- /bin/bash |
Open shell inside a pod. |
| Get namespaces | kubectl get namespaces |
List all namespaces. |
| Set context | kubectl config use-context <context-name> |
Switch between Kubernetes contexts. |
| Delete deployment | kubectl delete deployment <name> |
Remove a deployment. |