Kubernetes / kubectl Cheat Sheet
Aranabilir, yazdırılabilir bir kubectl referansı — context'ler, pod'lar, deployment'lar, service'ler, config ve secret'lar, ölçekleme ve sorun giderme. Ücretsiz.
kubectl basics
13kubectl get pods
kubectl get pods -o wide
kubectl get all
kubectl describe pod my-pod
kubectl logs my-pod
kubectl logs -f my-pod
kubectl logs my-pod -c sidecar
kubectl logs my-pod --previous
kubectl exec -it my-pod -- sh
kubectl exec my-pod -- env
kubectl get pod my-pod -o yaml
kubectl explain deployment.spec
kubectl api-resources
Contexts & namespaces
11kubectl config get-contexts
kubectl config current-context
kubectl config use-context prod
kubectl get namespaces
kubectl get pods -n kube-system
kubectl get pods -A
kubectl config set-context --current --namespace=dev
kubectl create namespace staging
kubectl delete namespace staging
kubectl config view --minify
export KUBECONFIG=~/.kube/other-config
Creating & applying resources
12kubectl apply -f app.yaml
kubectl apply -f ./manifests/
kubectl apply -k ./overlays/prod
kubectl delete -f app.yaml
kubectl create deployment web --image=nginx
kubectl run tmp --image=busybox -it --rm -- sh
--dry-run=client -o yaml
kubectl diff -f app.yaml
kubectl edit deployment web
kubectl patch deploy web -p '{"spec":{"replicas":3}}'
kubectl label pod my-pod env=prod
kubectl annotate pod my-pod note="checked"
Pods & debugging
13kubectl get pods -w
kubectl get pods -l app=web
kubectl get events --sort-by=.lastTimestamp
kubectl top pods
kubectl port-forward pod/my-pod 8080:80
kubectl cp my-pod:/var/log/app.log ./app.log
kubectl debug my-pod -it --image=busybox
kubectl debug node/my-node -it --image=busybox
kubectl delete pod my-pod
kubectl delete pod my-pod --grace-period=0 --force
kubectl get pod my-pod -o jsonpath='{.status.phase}'
CrashLoopBackOff
ImagePullBackOff
Deployments & rollouts
12kubectl get deployments
kubectl set image deploy/web web=nginx:1.27
kubectl rollout status deploy/web
kubectl rollout history deploy/web
kubectl rollout undo deploy/web
kubectl rollout undo deploy/web --to-revision=2
kubectl rollout restart deploy/web
kubectl rollout pause deploy/web
kubectl rollout resume deploy/web
kubectl scale deploy/web --replicas=5
maxSurge: 1, maxUnavailable: 0
kubectl get rs
Services & networking
12kubectl get svc
kubectl expose deploy/web --port=80 --target-port=8080
type: ClusterIP
type: NodePort
type: LoadBalancer
kubectl get endpoints web
kubectl port-forward svc/web 8080:80
kubectl get ingress
web.default.svc.cluster.local
kubectl run curl --image=curlimages/curl -it --rm -- sh
kubectl get networkpolicies
sessionAffinity: ClientIP
Config & secrets
11kubectl create configmap app-cfg --from-literal=ENV=prod
kubectl create configmap app-cfg --from-file=config.ini
kubectl create secret generic db --from-literal=pass=s3cret
kubectl get secret db -o jsonpath='{.data.pass}' | base64 -d
envFrom:
- configMapRef:
name: app-cfg
env:
- name: DB_PASS
valueFrom:
secretKeyRef:
name: db
key: pass
volumes:
- name: cfg
configMap:
name: app-cfg
kubectl create secret tls web-tls --cert=tls.crt --key=tls.key
kubectl create secret docker-registry regcred --docker-server=...
imagePullSecrets: [{name: regcred}]
kubectl rollout restart deploy/web
Scaling & autoscaling
11kubectl scale deploy/web --replicas=10
kubectl autoscale deploy/web --min=2 --max=10 --cpu-percent=70
kubectl get hpa
resources:
requests:
cpu: 100m
memory: 128Mi
resources:
limits:
cpu: 500m
memory: 256Mi
cpu: 100m
kubectl top pods --sort-by=memory
OOMKilled (exit code 137)
kubectl get pdb
minAvailable: 1
kubectl scale deploy/web --replicas=0
Nodes & cluster admin
12kubectl get nodes
kubectl describe node my-node
kubectl top nodes
kubectl cordon my-node
kubectl drain my-node --ignore-daemonsets
kubectl uncordon my-node
kubectl taint nodes my-node key=value:NoSchedule
nodeSelector: { disktype: ssd }
kubectl cluster-info
kubectl version
kubectl auth can-i delete pods
kubectl get componentstatuses
YAML manifest skeletons
9apiVersion: apps/v1
kind: Deployment
metadata:
name: web
spec:
replicas: 3
selector:
matchLabels:
app: web
template:
metadata:
labels:
app: web
spec:
containers:
- name: web
image: nginx:1.27
ports:
- containerPort: 80
apiVersion: v1
kind: Service
metadata:
name: web
spec:
selector:
app: web
ports:
- port: 80
targetPort: 80
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: web
spec:
rules:
- host: example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: web
port:
number: 80
apiVersion: v1
kind: ConfigMap
metadata:
name: app-cfg
data:
APP_ENV: production
livenessProbe:
httpGet:
path: /healthz
port: 80
initialDelaySeconds: 10
readinessProbe:
httpGet:
path: /ready
port: 80
apiVersion: batch/v1
kind: CronJob
metadata:
name: cleanup
spec:
schedule: "0 3 * * *"
jobTemplate:
spec:
template:
spec:
containers:
- name: job
image: busybox
command: ["sh", "-c", "echo run"]
restartPolicy: OnFailure
securityContext:
runAsNonRoot: true
readOnlyRootFilesystem: true
# kubectl create deploy web --image=nginx --dry-run=client -o yaml
Troubleshooting one-liners
13kubectl get pods -A | grep -v Running
kubectl get events -A --sort-by=.lastTimestamp | tail -20
kubectl describe pod my-pod | grep -A5 Events
kubectl logs -l app=web --tail=50
kubectl get pods --field-selector=status.phase=Failed
kubectl delete pods --field-selector=status.phase=Succeeded
kubectl get pods -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.status.phase}{"\n"}{end}'
kubectl get deploy web -o jsonpath='{.spec.template.spec.containers[0].image}'
kubectl rollout status deploy/web --timeout=120s
kubectl exec -it my-pod -- nslookup web
kubectl get pod my-pod -o yaml | grep -A5 lastState
kubectl api-resources --verbs=list -o name | xargs -n1 kubectl get -n dev
watch kubectl get pods
“:q” ile eşleşen bir girdi yok.
Kubernetes / kubectl Cheat Sheet Hakkında
Bu Kubernetes cheat sheet, kubectl'i tek bir aranabilir sayfaya koyar: kubectl temelleri, context'ler ve namespace'ler, kaynak oluşturma ve uygulama, pod'lar ve debug, deployment'lar ve rollout'lar, service'ler ve ağ, config ve secret'lar, ölçekleme ve otomatik ölçekleme, node'lar ve küme yönetimi, YAML manifest iskeletleri ve sorun giderme tek satırları.
Baskı altında çalıştırdığınız komutlar etrafında inşa edilmiştir — çökme döngüsündeki bir pod'u tanımlama, önceki container'dan log takibi, çalışan bir container'a exec ile girme, bir deployment'ı geri alma, bir service'e port yönlendirme — bayraklar kubectl --help'e bırakılmadan tam olarak yazılmış halde.
Bu gruptaki her cheat sheet gibi ücretsiz ve istemci tarafındadır: arama kutusuyla satırları canlı olarak filtreleyin, yapışkan içindekiler tablosundan bölümler arasında atlayın, herhangi bir komutu tek tıklamayla kopyalayın ve terminalinizin yanında referans olarak yazdırın.
Kubernetes / kubectl Cheat Sheet Nasıl Kullanılır
- Sayfayı açın ve kubectl temellerinden Sorun giderme tek satırlarına kadar bölümleri gözden geçirin.
- logs, rollout veya port-forward gibi bir anahtar kelime arayarak her satırı canlı olarak filtreleyin.
- Başlangıç Deployment, Service veya ConfigMap'e ihtiyacınız olduğunda YAML manifest iskeletleri bölümüne atlayın.
- Doğrudan terminalinize kopyalamak için bir komuta veya kopyala simgesine tıklayın.
- Tam kubectl referansının kağıt kopyası için Yazdır'ı kullanın.