Quick Reference

Cheatsheets

Practical command references for Linux, networking, servers, containers, databases, and more.

Cheatsheet#kubernetes-cheatsheet

Kubernetes (kubectl) Cheatsheet

Kubernetes (K8s) is an open-source system for automating deployment, scaling, and management of containerized applications. kubectl is the command-line tool used to interact with the K8s API.

Cluster Info and Context

kubectl cluster-info           # Display cluster information
kubectl get nodes              # List all nodes in the cluster
kubectl config get-contexts    # List all available contexts (clusters)
kubectl config use-context <name> # Switch to a different context

Managing Pods

kubectl get pods               # List all pods in the current namespace
kubectl get pods -A            # List all pods across all namespaces
kubectl get pods -o wide       # List pods with more details (IP, Node)
kubectl describe pod <pod-name> # Show detailed info about a pod
kubectl delete pod <pod-name>  # Delete a pod

Deployments and Scaling

kubectl get deployments        # List all deployments
kubectl create deployment nginx --image=nginx # Create a simple deployment
kubectl scale deployment nginx --replicas=3   # Scale deployment to 3 replicas
kubectl rollout status deployment/nginx       # Check rollout status
kubectl rollout undo deployment/nginx         # Rollback to the previous version

Services and Networking

kubectl get services           # List all services
kubectl expose deployment nginx --port=80 --type=LoadBalancer # Expose deployment via LoadBalancer
kubectl port-forward pod/nginx-123 8080:80    # Forward local port 8080 to pod port 80

Logs and Debugging

kubectl logs <pod-name>        # View logs of a pod
kubectl logs -f <pod-name>     # Follow logs of a pod
kubectl logs <pod-name> -c <container-name> # Logs for a specific container in a pod
kubectl exec -it <pod-name> -- /bin/bash    # Open an interactive shell in a pod

Applying and Managing Resources

kubectl apply -f manifest.yaml # Create or update resources from a YAML file
kubectl delete -f manifest.yaml # Delete resources defined in a YAML file
kubectl get all                # List all standard resources in the namespace