Kubernetes

Kubectl CLI Cheatsheet

Kubernetes kubectl commands for managing pods, deployments, services, and clusters.

27 commands
Windows MacOS Linux
#kubernetes #k8s #orchestration #Popular

Cluster Info

Display cluster info
kubectl cluster-info
List nodes
kubectl get nodes
View kubeconfig
kubectl config view
Switch context
kubectl config use-context <ctx>

Pods

List pods
kubectl get pods
List all namespaces
kubectl get pods -A
Pod details
kubectl describe pod <name>
View pod logs
kubectl logs <pod>
Stream logs
kubectl logs -f <pod>
Shell into pod
kubectl exec -it <pod> -- bash
Delete pod
kubectl delete pod <name>

Deployments

List deployments
kubectl get deployments
kubectl create deployment <name> --image=<img>
kubectl scale deployment <name> --replicas=3
kubectl rollout status deployment <name>
kubectl rollout undo deployment <name>

Services & Networking

List services
kubectl get services
Short form
kubectl get svc
kubectl expose deployment <name> --port=80
List ingress
kubectl get ingress

Apply & Debug

kubectl apply -f <file.yaml> # Apply config
kubectl delete -f <file.yaml># Delete from file
View events
kubectl get events
Resource usage
kubectl top pods

Quick Commands

List all pods with extra details
kubectl get pods -A -o wide
Stream logs from specific container
kubectl logs -f <pod> -c <container>
Apply configuration from file
kubectl apply -f deployment.yaml