Skip to content

ورقة غش Kubernetes

Kubernetes، واختصارها K8s (حيث يحل الرقم “8” محل الحروف الثمانية في كلمة “ubernete”)، هو نظام مفتوح المصدر لإدارة التطبيقات المعبأة في حاويات عبر مضيفين متعددين في منصة سحابية. الهدف من Kubernetes هو جعل نشر التطبيقات المعبأة بسيطاً وفعالاً (قوياً). يوفر Kubernetes آليات لنشر التطبيقات، والجدولة، والتحديثات، والصيانة.

عرض معلومات الموارد

العقد (Nodes)

اسم المورد: nodes، الاختصار: no

$ kubectl get no          # عرض جميع العقد
$ kubectl get no -o wide  # عرض مزيد من المعلومات حول جميع العقد
$ kubectl describe no     # عرض تفاصيل العقدة
$ kubectl get no -o yaml  # عرض تفاصيل العقدة بتنسيق YAML
$ kubectl get node --selector=[label_name] # تصفية العقد حسب ملصق معين
$ kubectl get nodes -o jsonpath='{.items[*].status.addresses[?(@.type=="ExternalIP")].address}'
# إخراج معلومات الحقل المحددة بواسطة تعبير jsonpath
$ kubectl top node [node_name] # عرض استهلاك العقدة (CPU/الذاكرة/التخزين)

القرون (Pods)

اسم المورد: pods، الاختصار: po

$ kubectl get po 				# عرض جميع القرون
$ kubectl get po -o wide
$ kubectl describe po
$ kubectl get po --show-labels 	# عرض ملصقات القرون
$ kubectl get po -l app=nginx
$ kubectl get po -o yaml
$ kubectl get pod [pod_name] -o yaml --export
$ kubectl get pod [pod_name] -o yaml --export > nameoffile.yaml 
# تصدير معلومات القرن إلى ملف YAML
$ kubectl get pods --field-selector status.phase=Running 		
# تصفية معلومات القرون باستخدام محددات الحقول

مساحات الأسماء (Namespaces)

اسم المورد: namespaces، الاختصار: ns

$ kubectl get ns
$ kubectl get ns -o yaml
$ kubectl describe ns

عمليات النشر (Deployments)

اسم المورد: deployments، الاختصار: deploy

$ kubectl get deploy
$ kubectl describe deploy
$ kubectl get deploy -o wide 
$ kubectl get deploy -o yaml

الخدمات (Services)

اسم المورد: services، الاختصار: svc

$ kubectl get svc
$ kubectl describe svc
$ kubectl get svc -o wide 
$ kubectl get svc -o yaml
$ kubectl get svc --show-labels

مجموعات الشياطين (DaemonSets)

اسم المورد: daemonsets، الاختصار: ds

$ kubectl get ds
$ kubectl describe ds --all-namespaces
$ kubectl describe ds [daemonset_name] -n [namespace_name]
$ kubectl get ds [ds_name] -n [ns_name] -o yaml

الأحداث (Events)

اسم المورد: events، الاختصار: ev

$ kubectl get events 
$ kubectl get events -n kube-system
$ kubectl get events -w

السجلات (Logs)

$ kubectl logs [pod_name]
$ kubectl logs --since=1h [pod_name]
$ kubectl logs --tail=20 [pod_name]
$ kubectl logs -f -c [container_name] [pod_name]
$ kubectl logs [pod_name] > pod.log

حسابات الخدمة (Service Accounts)

اسم المورد: serviceaccounts، الاختصار: sa

$ kubectl get sa
$ kubectl get sa -o yaml
$ kubectl get serviceaccounts default -o yaml >./sa.yaml
$ kubectl replace serviceaccount default -f ./sa.yaml

مجموعات النسخ المتماثلة (ReplicaSets)

اسم المورد: replicasets، الاختصار: rs

$ kubectl get rs
$ kubectl describe rs
$ kubectl get rs -o wide 
$ kubectl get rs -o yaml

الأدوار (Roles)

$ kubectl get roles --all-namespaces
$ kubectl get roles --all-namespaces -o yaml

الأسرار (Secrets)

$ kubectl get secrets
$ kubectl get secrets --all-namespaces 
$ kubectl get secrets -o yaml

خرائط التكوين (ConfigMaps)

اسم المورد: configmaps، الاختصار: cm

$ kubectl get cm
$ kubectl get cm --all-namespaces
$ kubectl get cm --all-namespaces -o yaml

المداخل (Ingresses)

اسم المورد: ingresses، الاختصار: ing

$ kubectl get ing
$ kubectl get ing --all-namespaces

الأحجام المستمرة (PersistentVolumes)

اسم المورد: persistentvolumes، الاختصار: pv

$ kubectl get pv 
$ kubectl describe pv

مطالبات الأحجام المستمرة (PersistentVolumeClaims)

اسم المورد: persistentvolumeclaims، الاختصار: pvc

$ kubectl get pvc
$ kubectl describe pvc

فئات التخزين (StorageClasses)

اسم المورد: storageclasses، الاختصار: sc

$ kubectl get sc
$ kubectl get sc -o yaml

موارد متعددة

$ kubectl get svc, po
$ kubectl get deploy, no
$ kubectl get all
$ kubectl get all --all-namespaces

تعديل سمات الموارد

الوصمات (Taints)

$ kubectl taint [node_name] [taint_name]

الملصقات (Labels)

$ kubectl label [node_name] disktype=ssd 
$ kubectl label [pod_name] env=prod

الحظر / رفع الحظر (Cordon / Uncordon)

$ kubectl cordon [node_name]   # حظر العقدة
$ kubectl uncordon [node_name] # رفع الحظر عن العقدة

تفريغ العقد (Draining Nodes)

$ kubectl drain [node_name]    # تفريغ العقدة

العقد / القرون

$ kubectl delete node [node_name] 
$ kubectl delete pod [pod_name]
$ kubectl edit node [node_name]
$ kubectl edit pod [pod_name]

عمليات النشر / مساحات الأسماء

$ kubectl edit deploy [deploy_name]
$ kubectl delete deploy [deploy_name]
$ kubectl expose deploy [deploy_name] --port=80 --type=NodePort
$ kubectl scale deploy [deploy_name] --replicas=5
$ kubectl delete ns
$ kubectl edit ns [ns_name]

الخدمات

$ kubectl edit svc [svc_name]
$ kubectl delete svc [svc_name]

مجموعات الشياطين

$ kubectl edit ds [ds_name] -n kube-system 
$ kubectl delete ds [ds_name]

حسابات الخدمة

$ kubectl edit sa [sa_name]
$ kubectl delete sa [sa_name]

التعليقات التوضيحية (Annotations)

$ kubectl annotate po [pod_name] [annotation]
$ kubectl annotate no [node_name]

إضافة الموارد

إنشاء القرون

$ kubectl create -f [name_of_file] 
$ kubectl apply -f [name_of_file]
$ kubectl run [pod_name] --image=nginx --restart=Never
$ kubectl run [pod_name] --generator=run-pod/v1 --image=nginx
$ kubectl run [pod_name] --image=nginx --restart=Never

إنشاء الخدمات

$ kubectl create svc nodeport [svc_name] --tcp=8080:80

إنشاء عمليات النشر

$ kubectl create -f [name_of_file] 
$ kubectl apply -f [name_of_file]
$ kubectl create deploy [deploy_name] --image=nginx

التفاعل مع الحاوية

$ kubectl run [pod_name] --image=busybox --rm -it --restart=Never -- sh

إخراج ملفات YAML

$ kubectl create deploy [deploy_name] --image=nginx --dry-run -o yaml > deploy.yaml
$ kubectl get po [pod_name] -o yaml --export > pod.yaml

الحصول على المساعدة

$ kubectl -h
$ kubectl create -h
$ kubectl run -h
$ kubectl explain deploy.spec

الطلبات

استدعاءات API

$ kubectl get --raw /apis/metrics.k8s.io/

معلومات المجموعة

$ kubectl config
$ kubectl cluster-info
$ kubectl get componentstatus