Community Tutorials Kubernetes كيفية كشف خدمة Kubernetes باستخدام NodePort
كيفية كشف خدمة Kubernetes باستخدام NodePort
KUBERNETES

كيفية كشف خدمة Kubernetes باستخدام NodePort

SKYLINE Knowledge Base
Photo by Growtika on Unsplash

دليل عملي خطوة بخطوة لـ كيفية كشف خدمة Kubernetes باستخدام NodePort. أوامر مختبرة في الإنتاج، متطلبات مسبقة، تحقق نهائي وروابط لمواضيع ذات صلة.

Service في Kubernetes يمنح Pods عنوان IP افتراضيًا ثابتًا واسم DNS. NodePort هو أبسط نوع لكشف Pod خارج العنقود.

المتطلبات المسبقة

  • عنقود يعمل، kubectl get nodes يعمل.
  • Deployment أو Pod للكشف — دليل Pod.

الخطوة 1: ثلاثة أنواع

  • ClusterIP — داخلي فقط
  • NodePort — منفذ عالي 30000-32767 على كل عقدة
  • LoadBalancer — LB سحابي

الخطوة 2: أنشئ Deployment

kubectl create deployment hello --image=nginxdemos/hello:latest --replicas=2
kubectl get deploy hello
kubectl get pods -l app=hello -o wide

الخطوة 3: كشف بـ NodePort

kubectl expose deployment hello --port=80 --target-port=80 --type=NodePort
kubectl get svc hello
curl http://node1.example.sa:31472/

الخطوة 4: تصريحي

service.yaml:

apiVersion: v1
kind: Service
metadata:
  name: hello
spec:
  type: NodePort
  selector:
    app: hello
  ports:
    - name: http
      port: 80
      targetPort: 80
      nodePort: 30080
kubectl apply -f service.yaml

الخطوة 5: اختبار توزيع الحمل

for i in $(seq 1 20); do
  curl -s http://node1.example.sa:30080/ | grep "Server name"
done | sort | uniq -c

الخطوة 6: التصحيح الشائع

kubectl describe svc hello
kubectl get endpoints hello
kubectl logs -l app=hello --tail=20 -f
kubectl get pods -l app=hello -o wide

إذا أظهر endpoints قيمة <none>، فالـ selector لا يطابق أي تسميات Pod.

الخطوة 7: الانتقال إلى Ingress

NodePort مناسب لاختبارين. للإنتاج العام، ضع Ingress controller (Traefik / nginx-ingress) أمامه.

التحقق

kubectl get svc -o wide
kubectl get endpoints
ss -tlnp | grep 30080
curl -fI http://node.example.sa:30080/

الخاتمة

NodePort أبسط طريقة محمولة لإيصال الحركة إلى Pod.

الخطوات التالية

SKYLINE Engineering

@skyline

The engineering team at SKYLINE Industrial Solutions. We publish field-tested guides drawn from real KSA and GCC deployments.

See author profile
SKYLINE engineering services

Need this implemented for you?

Reading is free — building it right takes a team. SKYLINE engineers ship Kubernetes for Aramco vendors, banks, hospitals and government agencies across Saudi Arabia. Talk to us before you start.

Aramco Approved Contractor ISO 9001 · ISO 27001 SAMA CSF aligned NCA ECC ready 247+ KSA clients

Comments

0 total · 0 threads
Be the first to leave a comment.