Kubernetes Pod Debug Cheat Sheet
Production’da bir pod ayağa kalkmıyorsa her saniye önemlidir. Bu cheat sheet, pod otopsisini sistematik hale getirir: 3 başlangıç komutu, 6 hata senaryosu ve 45 dakika tasarruf ettiren debug sırası.
kubectl get pod <pod> -n <ns> kubectl describe pod <pod> -n <ns> kubectl logs <pod> -n <ns> -c <container> --previous
- 1Status
- 2Events
- 3Last State
- 4Exit Code
- 5Restarts
- 6Logs
-c <container> bayrağını kullanın — aksi hâlde yanlış konteynerin loglarına bakıyor olabilirsiniz.kubectl describe pod <pod> -n <ns>kubectl get nodeskubectl get pvc -n <ns>
- FailedScheduling
- Insufficient cpu / memory
- taint/toleration uyuşmazlığı
- nodeSelector/affinity uyuşmazlığı
- Quota aşımı
- PVC Pending veya bağlı değil
- storage class uyuşmazlığı
- Request'leri düşür
- Kapasite ekle
- Taint/toleration düzelt
- Quota güncelle
- Storage bağla
kubectl logs <pod> -n <ns> -c <container> --previouskubectl describe pod <pod> -n <ns>
- Exit Code 1 → app/config hatası
- Exit Code 137 → OOMKilled
- Exit Code 126 → çalıştırılamaz komut
- Exit Code 127 → komut bulunamadı
- Eksik env var
- Hatalı başlangıç komutu
- Başarısız bağımlılık
- Önceki logları oku
- Last State/Reason'ı doğrula
- Exit code'u eşle
- App, config, komut veya bağımlılığı düzelt
kubectl describe pod <pod> -n <ns>kubectl top pod <pod> -n <ns>kubectl get pod <pod> -n <ns> -o jsonpath='{.spec.containers[*].resources}'
- Reason: OOMKilled
- Exit Code 137
- Limit kullanıma göre çok düşük
- Ani bellek spike'ı
- Trafik sonrası restart
- Limit'i artır
- Request'i gerçekçi ayarla
- Bellek profilini çıkar
- Memory leak'i düzelt
kubectl top için Metrics Server kurulu olmalıdır.kubectl get pod <pod> -n <ns> -o jsonpath='{.status.initContainerStatuses}'kubectl logs <pod> -n <ns> -c <init-container>
- DB migration hatası
- Bağımlılık erişilemiyor
- Eksik Secret
- İzin sorunu
- DNS hatası
- Hatalı bekleme mantığı
- Bağımlılığı düzelt
- Secret, DB bağlantısını kontrol et
- Migration script'ini doğrula
- DNS veya bekleme koşulunu düzelt
kubectl describe pod <pod> -n <ns>kubectl describe serviceaccount <sa> -n <ns>
- manifest unknown
- repository does not exist
- pull access denied
- authentication required
- Hatalı image tag
- Yanlış registry URL
- Eksik imagePullSecret
- Image adı ve tag'i düzelt
- Registry auth'u doğrula
- imagePullSecret ekle
- Registry izinlerini düzelt
- serviceAccount referansını kontrol et
kubectl describe pod <pod> -n <ns>kubectl get cm -n <ns>kubectl get secret -n <ns>kubectl get pvc -n <ns>
- Eksik ConfigMap
- Eksik Secret
- Geçersiz env referansı
- Geçersiz volume mount
- İzin reddedildi
- PVC Pending veya bağlı değil
- Salt okunur dosya sistemi
- Mount path çakışması
- Config referanslarını düzelt
- Secret ve PVC'leri doğrula
- Mount ve izin ayarlarını düzelt
- Container runtime hatasını incele
# Mevcut pod'a debug container ekle kubectl debug -it <pod> -n <ns> \ --image=nicolaka/netshoot --target=<container> # Tek seferlik network debug pod'u başlat kubectl run netshoot -it --rm \ --image=nicolaka/netshoot \ --restart=Never -- sh
Sık Yapılan Hatalar
Exit code’ları karıştırmak: Exit Code 137 her zaman OOMKilled değildir — SIGKILL (sinyal 9) ile öldürülmüş olabilir. kubectl describe içindeki Reason alanı kesin cevabı verir.
kubectl logs → --previous kullanmamak: Pod yeniden başladıktan sonra mevcut log boştur. Crash’den önceki loglar için her zaman --previous ekleyin.
Tek konteynere odaklanmak: Init container başarısız olduğunda ana konteyner hiç başlamaz. kubectl get pod -o yaml ile initContainerStatuses listesini kontrol edin.
Resource request/limit karıştırmak: Scheduler kararlarını requests, OOM kararlarını limits belirler. İkisi birbirinden bağımsızdır — ikisini ayrı ayrı kontrol edin.