Saltar al contenido principal

Lab 4.1 - Servicios ClusterIP y NodePort

Objetivos​

Al final de este laboratorio, usted será capaz de:

  • Crear Servicios ClusterIP
  • Crear Servicios NodePort
  • Verificar los Endpoints
  • Probar la conectividad

Ejercicio 1: Servicio ClusterIP​

Paso 1: Crear 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

Paso 2: Crear un Servicio ClusterIP​

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

Paso 3: Probar​

# Ver el Servicio
kubectl get service web-service

# Ver los Endpoints
kubectl get endpoints web-service

# Probar desde un Pod
kubectl run test-pod --image=busybox --rm -it -- sh
# Dentro del Pod: wget -O- http://web-service

Ejercicio 2: Servicio NodePort​

Paso 1: Crear un Servicio NodePort​

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

Paso 2: Probar​

# Ver el Servicio
kubectl get service web-nodeport

# Acceder vía NodePort
# curl http://<node-ip>:30080

Limpieza​

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

Próximos Pasos​

Lab 4.2: Descubrimiento de Servicios con DNS


Laboratorio creado el: Diciembre 2024