Events, status, logs và production debugging
Troubleshoot theo reconciliation chain: desired object → controller/status → scheduling → kubelet/runtime → network/storage → application SLI. Mục tiêu không phải “chạy nhiều lệnh”, mà là thu hẹp failure domain bằng evidence và bảo toàn khả năng rollback.
Troubleshooting
Kubernetes là hệ thống reconciliation: object khai báo desired state, nhiều controller và node component cùng tiến dần actual state về desired state. Vì vậy debug hiệu quả phải trả lời tuần tự: object có đúng không, controller đã quan sát chưa, Pod có được schedule không, kubelet/runtime có chạy container không, dependency network/storage có sẵn sàng không, và cuối cùng user-facing SLI có đạt không.
Running nhưng không nhận traffic chưa đủ để kết luận application healthy; readiness, Service selector, EndpointSlice, port, policy và gateway vẫn có thể sai.Systematic flow
- Get: status, readiness, restart count, age, node, owner và rollout generation.
- Describe: Conditions, Events, scheduling decisions, probes, mounts, image pulls và container states.
- Logs: current logs; với container restart dùng thêm
--previous. Correlate timestamp với deploy/config change. - Resources: requests/limits, actual usage, QoS, node pressure, eviction signal và throttling/OOM evidence.
- Network: Service selectors, EndpointSlices, DNS, ports/targetPort, listen address, NetworkPolicy và ingress/gateway path.
- Storage: PVC/PV binding, attach/mount, access mode, topology và CSI events.
- Controller/release: rollout history, image/config diff, desired vs observed generation, canary/SLI và rollback path.
kubectl get pod -n <ns> -o wide
kubectl describe pod <pod> -n <ns>
kubectl logs <pod> -n <ns> -c <container> --previous
kubectl get events -n <ns> --sort-by=.lastTimestamp
kubectl get svc,endpointslice -n <ns>
Đây là triage sequence, không phải checklist cứng. Nếu symptom chỉ xuất hiện ở một Availability Zone, một node pool hoặc một version, hãy phân nhóm evidence theo dimension đó trước khi mở rộng phạm vi.
Common symptoms
| Triệu chứng | Failure domain thường gặp | Evidence ưu tiên | Action an toàn đầu tiên |
|---|---|---|---|
Pending | Thiếu CPU/memory; taint/toleration; affinity/topology; PVC; image pull secret | Pod Conditions, scheduler Events, PVC/PV status | Không nới constraint mù quáng; xác nhận bottleneck và capacity/headroom |
CrashLoopBackOff | Command/config/permission; probe; dependency; app exit | Container lastState/exit code, current + --previous logs | Freeze config/image diff; tránh restart thủ công làm mất evidence |
OOMKilled | Memory limit thấp; heap/native growth; burst traffic; leak | Last termination reason, memory working set/RSS, traffic rate, limit | Giảm tải hoặc rollback trước; chỉ tăng limit khi node capacity cho phép |
| Running nhưng không có traffic | Readiness; selector; EndpointSlice; targetPort/listen; NetworkPolicy; gateway | Ready condition, endpoints, port mapping, request path | Test từng hop từ Service đến Pod trước khi thay gateway/routing |
| Latency/error tăng sau deploy | Regression; cold cache; dependency saturation; rollout overlap | Version-sliced SLI, saturation, traces, rollout timeline | Stop/pause rollout hoặc rollback nếu error budget đang burn |
Observability
Quan sát theo nhiều lớp: API/control-plane latency và audit; scheduler attempts; controller workqueue/reconcile errors; kubelet/runtime/CNI/CSI; node CPU/memory/disk/PID; workload RED metrics (rate, errors, duration) và dependency saturation. Không có một signal đơn lẻ nào đủ để mô tả toàn incident.
| Lớp | Signals cần giữ | Câu hỏi chẩn đoán |
|---|---|---|
| Control plane | API latency/errors, admission failures, audit, scheduler/controller queue | Desired state có được accepted và reconciled kịp không? |
| Node/runtime | Node conditions, CPU/memory/disk/PID pressure, kubelet/runtime logs | Node có đủ tài nguyên và runtime có ổn định không? |
| Network/storage | CNI/CSI errors, EndpointSlices, DNS, attach/mount latency | Pod có reach dependency và data path có sẵn sàng không? |
| Application | Request rate, error rate, latency, queue depth, dependency metrics | User-visible impact bắt đầu lúc nào và tập trung ở version/tenant/region nào? |
Events hữu ích nhưng có tính tạm thời và có thể bị rate-limit; nếu incident evidence quan trọng, phải export hoặc gom về hệ thống quan sát tập trung. Tương tự, node/pod/container có lifecycle ngắn nên cluster-level logging cần backend độc lập với node và workload lifecycle.
Debug safely
Dùng ephemeral containers khi runtime image tối giản và cần công cụ debug; tránh sửa trực tiếp production container/image chỉ để “thử”. Mọi exec, port-forward, debug container và quyền đọc log/secret cần tuân thủ RBAC, audit và incident procedure.
- Chụp manifest/status/events/logs liên quan trước thay đổi; ghi timestamp và người thực hiện.
- Không paste Secret/token vào ticket/chat/log collector; redaction trước khi chia sẻ evidence.
- Ưu tiên read-only inspection; thay đổi có blast radius nhỏ, time-box và có rollback cụ thể.
- Nếu reproduce ở staging, vẫn phải so sánh live object, defaulting, mutation/admission và environment-dependent dependency.
- Khi tăng log verbosity, cân nhắc CPU/I/O, dữ liệu nhạy cảm và cách khôi phục cấu hình cũ.
Release validation
Controller báo rollout complete chỉ xác nhận trạng thái Kubernetes ở mức controller; nó không chứng minh request thực tế thành công. Validation production phải kết hợp rollout condition với user SLI, canary metrics, error-budget burn, dependency saturation và business signal phù hợp.
Rollback / forward-fix gate
- Define trước metric và threshold để pause, rollback hoặc continue.
- So sánh canary/new version với baseline theo cùng traffic window; tránh kết luận từ aggregate che khuất regression.
- Xác minh rollback tương thích schema/config/data. Nếu migration không backward-compatible, “kubectl rollout undo” có thể không đủ.
- Sau rollback, kiểm tra SLI phục hồi và backlog/dependency saturation giảm; rollback success ở controller chưa phải incident resolved.
kubectl rollout status deployment/<name> -n <ns>
kubectl rollout history deployment/<name> -n <ns>
# rollback chỉ khi compatibility và runbook cho phép
kubectl rollout undo deployment/<name> -n <ns>