قابل تلاش، قابل پرنٹ kubectl حوالہ: کانٹیکسٹس، پوڈز، ڈیپلائمنٹس، سروسز، کنفیگ اور سیکرٹس، سکیلنگ اور مسائل کا حل۔ مفت۔

kubectl basics

13
kubectl get pods
List pods in current namespace
kubectl get pods -o wide
Pods with node and IP details
kubectl get all
Pods, services, deployments...
kubectl describe pod my-pod
Full details + recent events
kubectl logs my-pod
Container stdout logs
kubectl logs -f my-pod
Stream logs (follow)
kubectl logs my-pod -c sidecar
Logs of a specific container
kubectl logs my-pod --previous
Logs from the crashed run
kubectl exec -it my-pod -- sh
Interactive shell in a pod
kubectl exec my-pod -- env
Run one command in a pod
kubectl get pod my-pod -o yaml
Live manifest as YAML
kubectl explain deployment.spec
Built-in field documentation
kubectl api-resources
All resource types + short names

Contexts & namespaces

11
kubectl config get-contexts
List configured clusters
kubectl config current-context
Show the active context
kubectl config use-context prod
Switch cluster/context
kubectl get namespaces
List namespaces
kubectl get pods -n kube-system
Target one namespace
kubectl get pods -A
All namespaces
kubectl config set-context --current --namespace=dev
Set default namespace
kubectl create namespace staging
Create a namespace
kubectl delete namespace staging
Delete namespace + contents
kubectl config view --minify
Active context config only
export KUBECONFIG=~/.kube/other-config
Use an alternate kubeconfig

Creating & applying resources

12
kubectl apply -f app.yaml
Create or update from a file
kubectl apply -f ./manifests/
Apply a whole directory
kubectl apply -k ./overlays/prod
Apply with kustomize
kubectl delete -f app.yaml
Delete what a file created
kubectl create deployment web --image=nginx
Quick deployment (imperative)
kubectl run tmp --image=busybox -it --rm -- sh
Throwaway interactive pod
--dry-run=client -o yaml
Generate YAML without creating
kubectl diff -f app.yaml
Preview changes before apply
kubectl edit deployment web
Edit a live resource in $EDITOR
kubectl patch deploy web -p '{"spec":{"replicas":3}}'
Patch a single field
kubectl label pod my-pod env=prod
Add a label
kubectl annotate pod my-pod note="checked"
Add an annotation

Pods & debugging

13
kubectl get pods -w
Watch pod status live
kubectl get pods -l app=web
Filter by label selector
kubectl get events --sort-by=.lastTimestamp
Recent cluster events
kubectl top pods
CPU / memory per pod
kubectl port-forward pod/my-pod 8080:80
Tunnel a pod port locally
kubectl cp my-pod:/var/log/app.log ./app.log
Copy files from a pod
kubectl debug my-pod -it --image=busybox
Attach an ephemeral container
kubectl debug node/my-node -it --image=busybox
Debug pod on a node
kubectl delete pod my-pod
Delete (controller recreates)
kubectl delete pod my-pod --grace-period=0 --force
Force-kill a stuck pod
kubectl get pod my-pod -o jsonpath='{.status.phase}'
Extract one field (jsonpath)
CrashLoopBackOff
Check logs --previous + probes
ImagePullBackOff
Check image name / registry auth

Deployments & rollouts

12
kubectl get deployments
List deployments
kubectl set image deploy/web web=nginx:1.27
Update the container image
kubectl rollout status deploy/web
Wait for rollout to finish
kubectl rollout history deploy/web
List past revisions
kubectl rollout undo deploy/web
Roll back to previous version
kubectl rollout undo deploy/web --to-revision=2
Roll back to a revision
kubectl rollout restart deploy/web
Restart all pods (new config)
kubectl rollout pause deploy/web
Pause a rollout
kubectl rollout resume deploy/web
Resume a paused rollout
kubectl scale deploy/web --replicas=5
Scale replica count
maxSurge: 1, maxUnavailable: 0
Zero-downtime rolling update
kubectl get rs
ReplicaSets behind deployments

Services & networking

12
kubectl get svc
List services
kubectl expose deploy/web --port=80 --target-port=8080
Create a service for a deploy
type: ClusterIP
Internal-only virtual IP (default)
type: NodePort
Expose on every node (30000+)
type: LoadBalancer
Cloud external load balancer
kubectl get endpoints web
Pods actually behind a service
kubectl port-forward svc/web 8080:80
Tunnel a service locally
kubectl get ingress
List ingress rules
web.default.svc.cluster.local
In-cluster DNS name format
kubectl run curl --image=curlimages/curl -it --rm -- sh
Test connectivity in-cluster
kubectl get networkpolicies
List traffic restrictions
sessionAffinity: ClientIP
Sticky sessions on a service

Config & secrets

11
kubectl create configmap app-cfg --from-literal=ENV=prod
ConfigMap from key=value
kubectl create configmap app-cfg --from-file=config.ini
ConfigMap from a file
kubectl create secret generic db --from-literal=pass=s3cret
Secret from key=value
kubectl get secret db -o jsonpath='{.data.pass}' | base64 -d
Decode a secret value
envFrom: - configMapRef: name: app-cfg
Inject all keys as env vars
env: - name: DB_PASS valueFrom: secretKeyRef: name: db key: pass
Inject one secret as env var
volumes: - name: cfg configMap: name: app-cfg
Mount a ConfigMap as files
kubectl create secret tls web-tls --cert=tls.crt --key=tls.key
TLS secret for ingress
kubectl create secret docker-registry regcred --docker-server=...
Private registry pull secret
imagePullSecrets: [{name: regcred}]
Use the pull secret in a pod
kubectl rollout restart deploy/web
Pick up changed config/secret

Scaling & autoscaling

11
kubectl scale deploy/web --replicas=10
Manual scaling
kubectl autoscale deploy/web --min=2 --max=10 --cpu-percent=70
Create an HPA
kubectl get hpa
Autoscaler status + targets
resources: requests: cpu: 100m memory: 128Mi
Requests: scheduling baseline
resources: limits: cpu: 500m memory: 256Mi
Limits: hard caps (OOMKill)
cpu: 100m
m = millicores (0.1 CPU)
kubectl top pods --sort-by=memory
Find the memory hogs
OOMKilled (exit code 137)
Pod exceeded its memory limit
kubectl get pdb
PodDisruptionBudgets
minAvailable: 1
PDB: keep pods during drains
kubectl scale deploy/web --replicas=0
Stop an app without deleting

Nodes & cluster admin

12
kubectl get nodes
List cluster nodes
kubectl describe node my-node
Capacity, allocations, taints
kubectl top nodes
CPU / memory per node
kubectl cordon my-node
Stop scheduling onto a node
kubectl drain my-node --ignore-daemonsets
Evict pods for maintenance
kubectl uncordon my-node
Allow scheduling again
kubectl taint nodes my-node key=value:NoSchedule
Repel pods without toleration
nodeSelector: { disktype: ssd }
Pin pods to labeled nodes
kubectl cluster-info
API server / DNS endpoints
kubectl version
Client and server versions
kubectl auth can-i delete pods
Check your RBAC permissions
kubectl get componentstatuses
Control plane health (legacy)

YAML manifest skeletons

9
apiVersion: 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
Minimal Deployment
apiVersion: v1 kind: Service metadata: name: web spec: selector: app: web ports: - port: 80 targetPort: 80
Minimal ClusterIP Service
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
Minimal Ingress
apiVersion: v1 kind: ConfigMap metadata: name: app-cfg data: APP_ENV: production
Minimal ConfigMap
livenessProbe: httpGet: path: /healthz port: 80 initialDelaySeconds: 10
Liveness probe (restart if dead)
readinessProbe: httpGet: path: /ready port: 80
Readiness probe (gate traffic)
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
Minimal CronJob
securityContext: runAsNonRoot: true readOnlyRootFilesystem: true
Container hardening basics
# kubectl create deploy web --image=nginx --dry-run=client -o yaml
Generate any skeleton fast

Troubleshooting one-liners

13
kubectl get pods -A | grep -v Running
Every unhealthy pod in cluster
kubectl get events -A --sort-by=.lastTimestamp | tail -20
Latest events, all namespaces
kubectl describe pod my-pod | grep -A5 Events
Jump straight to pod events
kubectl logs -l app=web --tail=50
Recent logs across all replicas
kubectl get pods --field-selector=status.phase=Failed
List failed pods
kubectl delete pods --field-selector=status.phase=Succeeded
Clean up completed pods
kubectl get pods -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.status.phase}{"\n"}{end}'
Custom name + phase table
kubectl get deploy web -o jsonpath='{.spec.template.spec.containers[0].image}'
Which image is deployed?
kubectl rollout status deploy/web --timeout=120s
Fail CI if rollout hangs
kubectl exec -it my-pod -- nslookup web
Test in-cluster DNS
kubectl get pod my-pod -o yaml | grep -A5 lastState
Why did it restart?
kubectl api-resources --verbs=list -o name | xargs -n1 kubectl get -n dev
Everything in a namespace
watch kubectl get pods
Poor man's live dashboard

کوئی اندراج “:q” سے میل نہیں کھاتا۔


Kubernetes / kubectl چیٹ شیٹ کے بارے میں

یہ Kubernetes چیٹ شیٹ kubectl کو ایک قابل تلاش صفحے پر رکھتی ہے: kubectl کی بنیادی باتیں، کانٹیکسٹس اور نیم اسپیسز، ریسورسز بنانا اور لاگو کرنا، پوڈز اور ڈیبگنگ، ڈیپلائمنٹس اور رول آؤٹس، سروسز اور نیٹ ورکنگ، کنفیگ اور سیکرٹس، سکیلنگ اور آٹو سکیلنگ، نوڈز اور کلسٹر ایڈمنسٹریشن، YAML مینی فیسٹ ڈھانچے، اور مسائل حل کرنے کے ایک سطری کمانڈز۔

یہ ان کمانڈز کے گرد بنی ہے جو آپ دباؤ میں چلاتے ہیں: بار بار کریش ہونے والے پوڈ کی وضاحت دیکھنا، پچھلے کنٹینر کے لاگز مسلسل دیکھنا، چلتے کنٹینر میں exec کرنا، ڈیپلائمنٹ کو واپس رول کرنا، سروس کو port-forward کرنا، فلیگز تفصیل سے لکھے ہوئے، kubectl --help پر چھوڑے ہوئے نہیں۔

اس گروپ کی ہر چیٹ شیٹ کی طرح یہ مفت اور کلائنٹ سائیڈ ہے: سرچ باکس سے قطاروں کو لائیو فلٹر کریں، چپکے رہنے والی فہرست مضامین سے حصوں کے درمیان کودیں، ایک کلک سے کوئی بھی کمانڈ کاپی کریں اور اپنے ٹرمینل کے پاس حوالے کے لیے صفحہ پرنٹ کریں۔

Kubernetes / kubectl چیٹ شیٹ استعمال کرنے کا طریقہ

  1. شیٹ کھولیں اور حصوں کا جائزہ لیں، kubectl basics سے لے کر Troubleshooting one-liners تک۔
  2. logs، rollout یا port-forward جیسا کوئی کلیدی لفظ تلاش کریں تاکہ ہر قطار لائیو فلٹر ہو جائے۔
  3. جب آپ کو ابتدائی Deployment، Service یا ConfigMap چاہیے ہو تو YAML manifest skeletons پر جائیں۔
  4. کمانڈ کو براہ راست اپنے ٹرمینل میں کاپی کرنے کے لیے اس پر یا اس کے کاپی آئیکن پر کلک کریں۔
  5. مکمل kubectl حوالے کی کاغذی کاپی کے لیے Print استعمال کریں۔

اکثر پوچھے جانے والے سوالات

گیارہ حصے: kubectl کی بنیادی باتیں، کانٹیکسٹس اور نیم اسپیسز، ریسورسز بنانا اور لاگو کرنا، پوڈز اور ڈیبگنگ، ڈیپلائمنٹس اور رول آؤٹس، سروسز اور نیٹ ورکنگ، کنفیگ اور سیکرٹس، سکیلنگ اور آٹو سکیلنگ، نوڈز اور کلسٹر ایڈمن، YAML مینی فیسٹ ڈھانچے، اور مسائل حل کرنے کے ایک سطری کمانڈز۔

جی ہاں۔ پوڈز اور ڈیبگنگ کا حصہ describe، --previous اور -f کے ساتھ logs، exec، ٹائم اسٹیمپ کے مطابق ترتیب شدہ events، اور ایفیمرل ڈیبگ کنٹینر کا احاطہ کرتا ہے۔

ایک مخصوص حصے میں Deployment، Service، ConfigMap، Secret، Ingress اور Job کے کم از کم ڈھانچے ہیں: کاپی کر کے بھرنے کے لیے کافی۔

جی ہاں۔ کسی بھی قطار یا اس کے کاپی آئیکن پر کلک کریں اور kubectl کمانڈ فوراً کاپی ہو جاتی ہے۔

جی ہاں، یہ مکمل طور پر مفت ہے اور بغیر لاگ ان کے آپ کے براؤزر میں چلتا ہے۔

شیئر کریں

مقبول تلاشیں
kubectl چیٹ شیٹ kubernetes چیٹ شیٹ kubectl کمانڈز kubectl get pods kubernetes yaml مثال kubectl debug pod kubernetes کمانڈز کی فہرست
مدد چاہیے؟
اس ٹول میں کوئی مسئلہ ملا؟ ہماری ٹیم کو بتائیں۔
مسئلہ رپورٹ کریں

اس مفت ٹول کو اپنی ویب سائٹ پر شامل کریں: نیچے دیا گیا کوڈ کاپی اور پیسٹ کریں۔