devops101 › Cheat sheet'ler › ☸️ kubectl cheat sheet

☸️ kubectl cheat sheet

Gözlem

kubectl get pods -ATüm namespace pod'ları
kubectl get pods -o wideNode ve IP ile
kubectl get all -n prodNamespace'teki başlıca nesneler
kubectl get events --sort-by=.lastTimestampSon olaylar
kubectl describe pod XAyrıntı + Events
kubectl top podsKaynak kullanımı
kubectl api-resourcesNesne türleri
kubectl explain pod.spec.containersAlan belgesi

Log ve hata ayıklama

kubectl logs X -fLog izle
kubectl logs X --previousÇöken önceki konteyner logu
kubectl logs X -c konteynerBelirli konteyner
kubectl exec -it X -- shPod içine gir
kubectl debug -it X --image=busybox --target=appGeçici debug konteyneri
kubectl port-forward svc/web 8080:80Yerel porta yönlendir
kubectl run test --rm -it --image=busybox -- shGeçici pod

Uygulama

kubectl apply -f dosya.yamlUygula
kubectl apply -k overlays/prodKustomize ile uygula
kubectl diff -f dosya.yamlUygulamadan farkı gör
kubectl apply --dry-run=server -f x.yamlSunucuda doğrula
kubectl delete -f dosya.yamlSil
kubectl edit deploy webCanlıda düzenle (dikkat)
kubectl label pod X app=webEtiket ekle
kubectl create secret generic s --from-literal=k=vSecret oluştur

Dağıtım yönetimi

kubectl scale deploy web --replicas=5Ölçekle
kubectl rollout status deploy/webGüncelleme durumu
kubectl rollout history deploy/webRevizyonlar
kubectl rollout undo deploy/webGeri al
kubectl rollout restart deploy/webYeniden başlat
kubectl set image deploy/web web=img:2İmajı güncelle
kubectl autoscale deploy web --min=2 --max=10 --cpu-percent=70HPA

Küme ve yetki

kubectl config get-contextsKontekstler
kubectl config use-context XKontekst değiştir
kubectl config set-context --current --namespace=prodVarsayılan namespace
kubectl get nodes -o wideNode'lar
kubectl cordon|drain|uncordon nodeBakım için node'u boşalt
kubectl auth can-i delete pods -n prodYetki sorgula
kubectl get endpoints svcService arkasındaki pod'lar

Teşhis kısayolları

PendingYer/kaynak yok: describe → Events
ImagePullBackOffİmaj adı/registry yetkisi
CrashLoopBackOfflogs --previous, env/secret/probe
OOMKilled (exit 137)Bellek limiti
EvictedNode kaynağı bitti
Service ulaşmıyorget endpoints boş mu, selector, readiness

Uygulamada aç ve alıştırmaları çöz →