Lab 3.4 - Configuração dos Health Checks
Objetivos
Ao final deste lab, você será capaz de:
- Configurar Liveness Probes
- Configurar Readiness Probes
- Utilizar Startup Probes
- Observar o comportamento das probes
Exercício 1: Liveness Probe
Etapa 1: Criar um Pod com Liveness Probe
Crie 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
Etapa 2: Aplicar e observar
kubectl apply -f pod-liveness.yaml
# Observar os eventos
kubectl describe pod liveness-pod
Exercício 2: Readiness Probe
Etapa 1: Criar um Pod com Readiness Probe
Crie 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
Etapa 2: Criar um Service
Crie service.yaml:
apiVersion: v1
kind: Service
metadata:
name: web-service
spec:
selector:
app: web
ports:
- port: 80
Etapa 3: Observar
# Ver os Endpoints
kubectl get endpoints web-service
# O Pod aparece nos Endpoints somente quando a readiness probe é bem-sucedida
Exercício 3: Startup Probe
Etapa 1: Criar um Pod com Startup Probe
Crie 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
Etapa 2: Observar
kubectl apply -f pod-startup.yaml
# Observar a inicialização
kubectl get pod startup-pod -w
# As liveness/readiness probes aguardam o sucesso da startup probe
Exercício 4: Probe com Falha
Etapa 1: Criar um Pod com probe que falha
Crie 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
Etapa 2: Observar o reinício
kubectl apply -f pod-failing.yaml
# Observar os reinícios
kubectl get pod failing-pod -w
# Ver os eventos
kubectl describe pod failing-pod
Limpeza
kubectl delete pod liveness-pod readiness-pod startup-pod failing-pod
kubectl delete service web-service
Perguntas para Reflexão
- Qual é a diferença entre liveness e readiness?
- Quando usar uma startup probe?
- O que acontece se uma liveness probe falhar?
- Por que as readiness probes são importantes para os Services?
Próximos Passos
Quiz Módulo 3: Valide seus conhecimentos
Módulo 4: Services e Networking
Lab criado em: Dezembro 2024