============================================================
KUBERNETES / KUBECTL COMMAND CHEAT SHEET
AWS EKS + SPRING BOOT
============================================================
# ==========================================================
# 1. KUBECTL / CLUSTER
# ==========================================================
kubectl version --client
kubectl cluster-info
kubectl config current-context
kubectl config get-contexts
kubectl config use-context <context-name>
# ==========================================================
# 2. NODES
# ==========================================================
kubectl get nodes
kubectl get nodes -o wide
kubectl describe node <node-name>
# ==========================================================
# 3. NAMESPACES
# ==========================================================
kubectl get namespaces
kubectl get ns
kubectl get all -n <namespace>
kubectl get all -n staging
# ==========================================================
# 4. PODS
# ==========================================================
kubectl get pods -n staging
kubectl get pods -o wide -n staging
kubectl get pods -w -n staging
kubectl describe pod <pod-name> -n staging
# ==========================================================
# 5. APPLICATION LOGS
# ==========================================================
kubectl logs <pod-name> -n staging
kubectl logs -f <pod-name> -n staging
kubectl logs --tail=100 <pod-name> -n staging
kubectl logs --since=30m <pod-name> -n staging
kubectl logs <pod-name> -c <container-name> -n staging
# ==========================================================
# 6. DEPLOYMENTS
# ==========================================================
kubectl get deployments -n staging
kubectl get deploy -n staging
kubectl describe deployment <deployment-name> -n staging
kubectl rollout status deployment/<deployment-name> -n staging
kubectl rollout history deployment/<deployment-name> -n staging
# ==========================================================
# 7. SERVICES
# ==========================================================
kubectl get services -n staging
kubectl get svc -n staging
kubectl describe service <service-name> -n staging
# ==========================================================
# 8. CONFIGMAPS
# ==========================================================
kubectl get configmaps -n staging
kubectl describe configmap <configmap-name> -n staging
# ==========================================================
# 9. SECRETS
# ==========================================================
kubectl get secrets -n staging
kubectl describe secret <secret-name> -n staging
# WARNING: May expose sensitive credentials
kubectl get secret <secret-name> -o yaml -n staging
# ==========================================================
# 10. EVENTS / TROUBLESHOOTING
# ==========================================================
kubectl get events -n staging
kubectl get events -n staging --sort-by=.lastTimestamp
# ==========================================================
# 11. EXECUTE COMMAND INSIDE POD
# ==========================================================
kubectl exec -it <pod-name> -n staging -- /bin/sh
kubectl exec -it <pod-name> -n staging -- /bin/bash
# Exit container
exit
# ==========================================================
# 12. RESTART DEPLOYMENT
# ==========================================================
kubectl rollout restart deployment/<deployment-name> -n staging
kubectl rollout status deployment/<deployment-name> -n staging
# ==========================================================
# 13. DELETE POD
# ==========================================================
kubectl delete pod <pod-name> -n staging
# ==========================================================
# 14. GET ALL RESOURCES
# ==========================================================
kubectl get all -n staging
# ==========================================================
# 15. SCALING
# ==========================================================
kubectl get deployment <deployment-name> -n staging
kubectl scale deployment <deployment-name> --replicas=3 -n staging
kubectl get pods -n staging
# ==========================================================
# 16. ROLLBACK
# ==========================================================
kubectl rollout history deployment/<deployment-name> -n staging
kubectl rollout undo deployment/<deployment-name> -n staging
kubectl rollout status deployment/<deployment-name> -n staging
# ==========================================================
# 17. FILTER BY LABEL
# ==========================================================
kubectl get pods -l app=<app-name> -n staging
kubectl get pods -l app=impress -n staging
kubectl get all -l app=impress -n staging
# ==========================================================
# 18. RESOURCE USAGE
# ==========================================================
kubectl top pods -n staging
kubectl top nodes
# ==========================================================
# 19. MOST IMPORTANT DAILY COMMANDS
# ==========================================================
kubectl config current-context
kubectl get ns
kubectl get pods -n staging
kubectl get pods -o wide -n staging
kubectl describe pod <pod-name> -n staging
kubectl logs <pod-name> -n staging
kubectl logs -f <pod-name> -n staging
kubectl get deploy -n staging
kubectl get svc -n staging
kubectl get events -n staging --sort-by=.lastTimestamp
# ==========================================================
# 20. SPRING BOOT / EKS TROUBLESHOOTING FLOW
# ==========================================================
kubectl config current-context
kubectl get ns
kubectl get pods -n <namespace>
kubectl get pods -o wide -n <namespace>
kubectl describe pod <pod-name> -n <namespace>
kubectl logs <pod-name> -n <namespace>
kubectl logs -f <pod-name> -n <namespace>
kubectl get events -n <namespace> --sort-by=.lastTimestamp
# ==========================================================
# 21. AWS EKS CONNECTION
# ==========================================================
# Check AWS identity
aws sts get-caller-identity
# If using a specific AWS profile
aws sts get-caller-identity --profile <profile-name>
# List EKS clusters
aws eks list-clusters --region <aws-region>
# Configure kubectl for an EKS cluster
aws eks update-kubeconfig \
--region <aws-region> \
--name <cluster-name>
# Example
aws eks update-kubeconfig \
--region us-east-1 \
--name staging-eksCluster-a11b87c
# Verify connection
kubectl cluster-info
# Check nodes
kubectl get nodes
# ==========================================================
# 22. QUICK EKS WORKFLOW
# ==========================================================
aws sts get-caller-identity
aws eks list-clusters --region <aws-region>
aws eks update-kubeconfig \
--region <aws-region> \
--name <cluster-name>
kubectl config current-context
kubectl get nodes
kubectl get ns
kubectl get pods -n staging
kubectl get deploy -n staging
kubectl get svc -n staging
kubectl logs -f <pod-name> -n staging
# ==========================================================
# IMPORTANT CONCEPTS
# ==========================================================
kubectl = Local Kubernetes command-line client
Cluster = Complete Kubernetes environment
Node = Machine/worker machine where Pods run
Pod = Kubernetes workload unit containing container(s)
Container = Actual application runtime, e.g. Spring Boot
Namespace = Logical separation inside a Kubernetes cluster
Deployment = Manages Pods, replicas and rolling updates
Service = Stable network endpoint for accessing Pods
ConfigMap = Non-sensitive application configuration
Secret = Sensitive configuration/credentials
RBAC = Kubernetes Role-Based Access Control
IAM = AWS identity and permission system
# ==========================================================
# KUBERNETES STRUCTURE
# ==========================================================
AWS EKS Cluster
|
+-- Node 1
| |
| +-- Pod
| | |
| | +-- Container
| | |
| | +-- Spring Boot Application
| |
| +-- Pod
|
+-- Node 2
| |
| +-- Pod
|
+-- Namespaces
|
+-- staging
+-- production
+-- monitoring
# ==========================================================
# APPLICATION DEBUGGING FLOW
# ==========================================================
Cluster
|
v
Namespace
|
v
Deployment
|
v
Pod
|
v
Container
|
v
Application Logs
# ==========================================================
# COMMON POD ERRORS
# ==========================================================
ImagePullBackOff
CrashLoopBackOff
Pending
FailedScheduling
FailedMount
ContainerCreating
Error
# ==========================================================
# SAFETY
# ==========================================================
# Always check which cluster you are connected to
kubectl config current-context
# Always check namespace before making changes
kubectl get ns
# Be careful with production:
kubectl delete ...
kubectl scale ...
kubectl rollout restart ...
kubectl rollout undo ...
# Be careful with secrets:
kubectl get secret <secret-name> -o yaml -n staging
