Capítulo 3.8 - Health Checks
Objetivos de Aprendizaje
Al final de este capítulo, usted será capaz de:
- Comprender los tres tipos de probes
- Configurar las Liveness Probes
- Configurar las Readiness Probes
- Utilizar las Startup Probes
- Elegir la estrategia adecuada de health check
Tipos de Probes
Kubernetes ofrece tres tipos de probes para verificar la salud de los contenedores:
1. Liveness Probe
Determina si el contenedor debe ser reiniciado.
Ejemplo
livenessProbe:
httpGet:
path: /health
port: 8080
initialDelaySeconds: 30
periodSeconds: 10
timeoutSeconds: 5
failureThreshold: 3
Comportamiento
Si la probe falla: El contenedor es reiniciado.
2. Readiness Probe
Determina si el contenedor está listo para recibir tráfico.
Ejemplo
readinessProbe:
httpGet:
path: /ready
port: 8080
initialDelaySeconds: 5
periodSeconds: 5
timeoutSeconds: 3
successThreshold: 1
failureThreshold: 3
Comportamiento
Si la probe falla: El Pod es retirado de los Endpoints del Service.
3. Startup Probe
Para aplicaciones lentas en iniciar.
Ejemplo
startupProbe:
httpGet:
path: /startup
port: 8080
failureThreshold: 30 # 30 intentos
periodSeconds: 10 # Cada 10 segundos
# Total: hasta 5 minutos
Comportamiento
Durante el startup: Las otras probes están desactivadas.
Tipos de Probes
HTTP GET
livenessProbe:
httpGet:
path: /health
port: 8080
httpHeaders:
- name: Custom-Header
value: Awesome
TCP Socket
livenessProbe:
tcpSocket:
port: 8080
Command Exec
livenessProbe:
exec:
command:
- cat
- /tmp/healthy
Configuración Completa
apiVersion: v1
kind: Pod
metadata:
name: healthy-pod
spec:
containers:
- name: app
image: my-app:1.0
ports:
- containerPort: 8080
livenessProbe:
httpGet:
path: /health
port: 8080
initialDelaySeconds: 30
periodSeconds: 10
failureThreshold: 3
readinessProbe:
httpGet:
path: /ready
port: 8080
initialDelaySeconds: 5
periodSeconds: 5
failureThreshold: 3
startupProbe:
httpGet:
path: /startup
port: 8080
failureThreshold: 30
periodSeconds: 10
Buenas Prácticas
Cuándo Utilizar Cada Probe
- Liveness: Si la aplicación puede quedarse bloqueada
- Readiness: Si la aplicación necesita tiempo para estar lista
- Startup: Si la aplicación inicia lentamente (>30s)
Parámetros Recomendados
- initialDelaySeconds: Lo suficientemente largo para el arranque
- periodSeconds: 5-10 segundos
- timeoutSeconds: 1-3 segundos
- failureThreshold: 3 (por defecto)
Resumen
En este capítulo, usted ha aprendido:
Liveness Probe: Reinicia el contenedor si falla
Readiness Probe: Retira el Pod del Service si no está listo
Startup Probe: Para aplicaciones lentas en iniciar
Tipos: HTTP GET, TCP Socket, Command Exec
Configuración: initialDelaySeconds, periodSeconds, failureThreshold
Próximos Pasos
Ahora que domina los Health Checks:
Lab 3.4: Configuración de Health Checks
Quiz Módulo 3: Valide sus conocimientos
Capítulo creado el: Diciembre 2024