DevOpsil
Kubernetes35 commands

kubectl Cheat Sheet

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

Cluster Info

CommandDescription
kubectl cluster-info
Display cluster info
kubectl get nodes
List all nodes
kubectl get nodes -o wide
List nodes with details
kubectl top nodes
Show node resource usage
kubectl describe node <name>
Detailed node info

Pods

CommandDescription
kubectl get pods
List pods in current namespace
kubectl get pods -A
List pods in all namespaces
kubectl get pods -o wide
List pods with node info
kubectl describe pod <name>
Detailed pod info
kubectl logs <pod>
View pod logs
kubectl logs <pod> -f
Stream pod logs
kubectl logs <pod> -c <container>
Logs from specific container
kubectl exec -it <pod> -- /bin/sh
Shell into a pod
kubectl delete pod <name>
Delete a pod
kubectl get pods --field-selector status.phase=Running
List running pods only

Deployments

CommandDescription
kubectl get deployments
List deployments
kubectl describe deployment <name>
Deployment details
kubectl scale deployment <name> --replicas=3
Scale a deployment
kubectl rollout status deployment/<name>
Check rollout status
kubectl rollout undo deployment/<name>
Rollback deployment
kubectl rollout history deployment/<name>
View rollout history
kubectl set image deployment/<name> <container>=<image>
Update container image

Services & Networking

CommandDescription
kubectl get svc
List services
kubectl expose deployment <name> --port=80 --type=LoadBalancer
Expose deployment
kubectl get ingress
List ingress resources
kubectl port-forward svc/<name> 8080:80
Port forward to service
kubectl get networkpolicies
List network policies

Config & Secrets

CommandDescription
kubectl get configmaps
List ConfigMaps
kubectl get secrets
List secrets
kubectl create secret generic <name> --from-literal=key=value
Create secret
kubectl create configmap <name> --from-file=<path>
Create ConfigMap from file

Namespaces & Context

CommandDescription
kubectl get namespaces
List namespaces
kubectl config get-contexts
List contexts
kubectl config use-context <name>
Switch context
kubectl config set-context --current --namespace=<ns>
Set default namespace