kubectl و YAML
ما هو kubectl؟
Section titled “ما هو kubectl؟”kubectl هو أداة سطر الأوامر التي تتواصل مع Kubernetes API Server.
kubectl get podskubectl apply -f app.yamlkubectl describe deployment webImperative vs Declarative
Section titled “Imperative vs Declarative”| الطريقة | مثال | متى تفيد؟ |
|---|---|---|
| Imperative | kubectl run nginx --image=nginx | تجربة سريعة أو امتحان |
| Declarative | kubectl apply -f deployment.yaml | العمل الحقيقي و GitOps |
أوامر يومية
Section titled “أوامر يومية”kubectl get allkubectl get pod web -o yamlkubectl describe pod webkubectl logs webkubectl apply -f app.yamlkubectl delete -f app.yamlkubectl explain deployment.specdry-run
Section titled “dry-run”يمكنك توليد YAML بسرعة:
kubectl create deployment web --image=nginx:1.27 --dry-run=client -o yamlقبل تطبيق تغيير:
kubectl diff -f deployment.yamlkubectl apply -f deployment.yamlلتغيير صغير وسريع:
kubectl patch deployment web -p '{"spec":{"replicas":4}}'context
Section titled “context”context يحدد Cluster و user و namespace الحالي.
kubectl config get-contextskubectl config current-contextkubectl config set-context --current --namespace=devLab: توليد YAML ثم تطبيقه
الهدف: استخدام dry-run لإنشاء Deployment manifest بدلا من كتابته من الصفر.
kubectl create deployment demo --image=nginx:1.27 --dry-run=client -o yaml > demo.yamlkubectl apply -f demo.yamlkubectl get deployment demokubectl delete -f demo.yaml