انتقل إلى المحتوى الرئيسي

المختبر 4.1 - خدمات ClusterIP و NodePort

الأهداف​

في نهاية هذا المختبر، ستكون قادرًا على:

  • إنشاء خدمات ClusterIP
  • إنشاء خدمات NodePort
  • التحقق من النقاط النهائية
  • اختبار الاتصال

التمرين 1: خدمة ClusterIP​

الخطوة 1: إنشاء نشر​

apiVersion: apps/v1
kind: Deployment
metadata:
name: web-deployment
spec:
replicas: 3
selector:
matchLabels:
app: web
template:
metadata:
labels:
app: web
spec:
containers:
- name: nginx
image: nginx:1.20

الخطوة 2: إنشاء خدمة ClusterIP​

apiVersion: v1
kind: Service
metadata:
name: web-service
spec:
type: ClusterIP
selector:
app: web
ports:
- port: 80
targetPort: 80

الخطوة 3: اختبار​

# عرض الخدمة
kubectl get service web-service

# عرض النقاط النهائية
kubectl get endpoints web-service

# اختبار من داخل بود
kubectl run test-pod --image=busybox --rm -it -- sh
# داخل البود: wget -O- http://web-service

التمرين 2: خدمة NodePort​

الخطوة 1: إنشاء خدمة NodePort​

apiVersion: v1
kind: Service
metadata:
name: web-nodeport
spec:
type: NodePort
selector:
app: web
ports:
- port: 80
targetPort: 80
nodePort: 30080

الخطوة 2: اختبار​

# عرض الخدمة
kubectl get service web-nodeport

# الوصول عبر NodePort
# curl http://<node-ip>:30080

التنظيف​

kubectl delete deployment web-deployment
kubectl delete service web-service web-nodeport

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

المختبر 4.2: اكتشاف الخدمة باستخدام DNS


تم إنشاء المختبر في: ديسمبر 2024