The Digital Nomad's Guide to kubectl - Kubernetes Cheatsheet
· 2 min read
In the neon-lit underbelly of the cloud, where containers dance like digital shadows and clusters hum with the rhythm of a thousand microservices, every DevOps engineer needs their tools of the trade. Here's your survival guide to kubectl, straight from the container trenches...
Chapter 1: Context Switching - The Art of Digital Shapeshifting
# List your available identities (contexts)
kubectl config get-contexts
# Assume a new identity (switch context)
kubectl config use-context <context-name>
# See your current digital footprint
kubectl config current-context
# The quick escape route - temporary context
KUBECONFIG=~/special-ops/config kubectl get pods
Chapter 2: Reconnaissance - Eyes in the Digital Sky
# Quick cluster status check
kubectl get nodes
kubectl get pods -A
kubectl top nodes # If metrics-server is your ally
# Deep dive into the pod matrix
kubectl describe pod <pod-name> -n <namespace>
kubectl logs -f <pod-name> -n <namespace> # Live feed
kubectl logs -p <pod-name> # Post-mortem analysis
# Secret surveillance
kubectl get secrets -n <namespace>
kubectl describe secret <secret-name> -n <namespace>
Chapter 3: Deployment Dance - The Art of Container Combat
# Deploy your digital agents
kubectl apply -f manifest.yml
kubectl apply -k ./ # Kustomize your reality
# Watch the deployment unfold
kubectl rollout status deployment/<name>
# When things go sideways
kubectl rollout undo deployment/<name>
kubectl rollout history deployment/<name>
# Force pod regeneration
kubectl rollout restart deployment/<name>
Chapter 4: Debug Protocols - When the Matrix Glitches
# Emergency pod creation for recon
kubectl run debugger --rm -i --tty --image=alpine -- sh
# Network diagnostics
kubectl port-forward <pod-name> 8080:80
kubectl proxy # Start your secure tunnel
# Resource examination
kubectl top pod <pod-name> -n <namespace>
kubectl describe node <node-name>
Chapter 5: The Cleanup Protocol - Digital Sanitation
# Clean up your tracks
kubectl delete -f manifest.yml
kubectl delete pod <pod-name> --grace-period=0 --force # The quick and dirty way
# Mass evacuation
kubectl delete namespace <namespace>
kubectl delete pods --all -n <namespace>
Chapter 6: Advanced Maneuvers - For the Digital Elite
# Multi-cluster operations
kubectl config use-context cluster1
kubectl get pods
kubectl config use-context cluster2
kubectl get pods
# Resource quotas check
kubectl describe quota -n <namespace>
# API resource discovery
kubectl api-resources
kubectl explain pod.spec
Chapter 7: The Watcher's Protocols - Monitoring the Digital Pulse
# Real-time pod monitoring
watch kubectl get pods -n <namespace>
# Events timeline
kubectl get events --sort-by='.metadata.creationTimestamp'
# Resource usage metrics
kubectl top pods -n <namespace>
kubectl top nodes --sort-by=cpu
Remember, in this digital wilderness, your kubectl commands are both your weapon and your shield. Use them wisely, keep your contexts clean, and always have an escape route planned. The container matrix is vast and unforgiving, but with these tools, you'll navigate it like a true digital nomad.
Quick Reference Matrix
| Operation | Command | Digital Footprint |
|---|---|---|
| Pod List | kubectl get pods -n <ns> | Light |
| Pod Details | kubectl describe pod <pod> | Medium |
| Log Stream | kubectl logs -f <pod> | Heavy |
| Exec Access | kubectl exec -it <pod> -- sh | Critical |
| Port Forward | kubectl port-forward <pod> 8080:80 | Medium |
End transmission. May your containers run true, and your clusters stay strong.
