ورقة غش 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