Aller au contenu principal

Lab 4.1 - Services ClusterIP et NodePort

Objectifs

À la fin de ce lab, vous serez capable de:

  • Créer des Services ClusterIP
  • Créer des Services NodePort
  • Vérifier les Endpoints
  • Tester la connectivité

Exercice 1: Service ClusterIP

Étape 1: Créer un Deployment

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

Étape 2: Créer un Service ClusterIP

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

Étape 3: Tester

# Voir le Service
kubectl get service web-service

# Voir les Endpoints
kubectl get endpoints web-service

# Tester depuis un Pod
kubectl run test-pod --image=busybox --rm -it -- sh
# Dans le Pod: wget -O- http://web-service

Exercice 2: Service NodePort

Étape 1: Créer un Service NodePort

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

Étape 2: Tester

# Voir le Service
kubectl get service web-nodeport

# Accéder via NodePort
# curl http://<node-ip>:30080

Nettoyage

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

Prochaines Étapes

Lab 4.2: Service Discovery avec DNS


Lab créé le: Décembre 2024