Saltar al contenido principal

Lab 3.4 - Configuración de Health Checks

Objetivos​

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

  • Configurar Liveness Probes
  • Configurar Readiness Probes
  • Utilizar Startup Probes
  • Observar el comportamiento de las probes

Ejercicio 1: Liveness Probe​

Paso 1: Crear un Pod con Liveness Probe​

Cree pod-liveness.yaml:

apiVersion: v1
kind: Pod
metadata:
name: liveness-pod
spec:
containers:
- name: nginx
image: nginx:1.20
livenessProbe:
httpGet:
path: /
port: 80
initialDelaySeconds: 10
periodSeconds: 5
failureThreshold: 3

Paso 2: Aplicar y observar​

kubectl apply -f pod-liveness.yaml

# Observar los eventos
kubectl describe pod liveness-pod

Ejercicio 2: Readiness Probe​

Paso 1: Crear un Pod con Readiness Probe​

Cree pod-readiness.yaml:

apiVersion: v1
kind: Pod
metadata:
name: readiness-pod
labels:
app: web
spec:
containers:
- name: nginx
image: nginx:1.20
readinessProbe:
httpGet:
path: /
port: 80
initialDelaySeconds: 5
periodSeconds: 5

Paso 2: Crear un Service​

Cree service.yaml:

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

Paso 3: Observar​

# Ver los Endpoints
kubectl get endpoints web-service

# El Pod aparece en los Endpoints solo cuando la readiness probe tiene éxito

Ejercicio 3: Startup Probe​

Paso 1: Crear un Pod con Startup Probe​

Cree pod-startup.yaml:

apiVersion: v1
kind: Pod
metadata:
name: startup-pod
spec:
containers:
- name: slow-app
image: busybox
command: ['sh', '-c', 'sleep 30 && echo "Ready" && sleep 3600']
startupProbe:
exec:
command: ['sh', '-c', 'echo "started"']
failureThreshold: 30
periodSeconds: 2
livenessProbe:
exec:
command: ['sh', '-c', 'echo "alive"']
periodSeconds: 10

Paso 2: Observar​

kubectl apply -f pod-startup.yaml

# Observar el arranque
kubectl get pod startup-pod -w

# Las liveness/readiness probes esperan a que startup tenga éxito

Ejercicio 4: Probe que Falla​

Paso 1: Crear un Pod con probe que falla​

Cree pod-failing.yaml:

apiVersion: v1
kind: Pod
metadata:
name: failing-pod
spec:
containers:
- name: nginx
image: nginx:1.20
livenessProbe:
httpGet:
path: /nonexistent
port: 80
initialDelaySeconds: 5
periodSeconds: 5
failureThreshold: 3

Paso 2: Observar el reinicio​

kubectl apply -f pod-failing.yaml

# Observar los reinicios
kubectl get pod failing-pod -w

# Ver los eventos
kubectl describe pod failing-pod

Limpieza​

kubectl delete pod liveness-pod readiness-pod startup-pod failing-pod
kubectl delete service web-service

Preguntas de Reflexión​

  1. ¿Cuál es la diferencia entre liveness y readiness?
  2. ¿Cuándo utilizar una startup probe?
  3. ¿Qué sucede si una liveness probe falla?
  4. ¿Por qué las readiness probes son importantes para los Services?

Próximos Pasos​

Quiz Módulo 3: Validar sus conocimientos
Módulo 4: Servicios y Networking


Lab creado el: Diciembre 2024