1 min read #devops
On this page

Kubernetes Operations Manual

Kubernetes is a container orchestration platform. Core concepts: pod (smallest scheduling unit), deployment (declarative pod management), service (stable network entry point), ingress (L7 routing), configmap/secret (configuration injection), namespace (resource isolation).

View

# Nodes
kubectl get nodes -o wide                               # Includes IP, OS, kubelet version
kubectl describe node <node>                            # Capacity, conditions, events

# Pods
kubectl get pods -A                                     # All namespaces
kubectl get pods -n <ns> -o wide                        # Includes IP, node, status
kubectl get pods -n <ns> --sort-by=.status.startTime    # Sort by creation time
kubectl get pods -n <ns> --field-selector status.phase=Running

# Describe (most common debugging command: check Events to see where it's stuck)
kubectl describe pod <pod> -n <ns>
# Events interpretation:
#   FailedScheduling → Insufficient resources or node affinity mismatch
#   Failed to pull image → Wrong image name/version or registry unreachable
#   CrashLoopBackOff → Container exits immediately after startup (check logs)

# Logs
kubectl logs <pod> -n <ns> --tail=100 -f
kubectl logs <pod> -n <ns> --previous                    # Logs from the previous crash
kubectl logs -l app=myapp -n <ns> --tail=50              # Label selector

# Other resources
kubectl get deploy,svc,ingress,cm,secret,pvc -n <ns>
kubectl get events -n <ns> --sort-by='.lastTimestamp'    # All events in the namespace
kubectl top pods -A                                      # Resource usage (requires metrics-server)
kubectl config get-contexts                              # Current kubeconfig context

Operations

kubectl apply -f manifest.yaml                           # Create/update
kubectl delete -f manifest.yaml
kubectl delete pod <pod> -n <ns>                        # Delete pod (deployment will recreate it)
kubectl rollout restart deployment/<name> -n <ns>        # Rolling restart
kubectl scale deployment/<name> --replicas=3 -n <ns>

kubectl exec -it <pod> -n <ns> -- sh
kubectl exec <pod> -n <ns> -- cat /etc/config
kubectl cp <pod>:/path/file ./file -n <ns>
kubectl port-forward <pod> 8080:80 -n <ns>               # Local debugging
kubectl config use-context <context>

Debugging

# Pod won't start: check Events
kubectl describe pod <pod> -n <ns> | tail -20

# View full YAML (including defaults + runtime state)
kubectl get pod <pod> -n <ns> -o yaml

# Temporary debugging container
kubectl run debug --rm -it --image=alpine -- sh

# RBAC permission check
kubectl auth can-i create pods --as=system:serviceaccount:<ns>:<sa>