← Về danh sách bài học Bài 16/25

💓 Bài 16: Liveness & Readiness Probes

⏱️ Thời gian: 20 phút | 📚 Độ khó: Trung bình

🎯 Sau bài học này, bạn sẽ:

1. Ba Loại Probes

Probe Mục đích Fail thì sao
Liveness Container còn sống? Restart container
Readiness Container sẵn sàng nhận traffic? Loại khỏi Service
Startup App đã start xong? Restart (slow start apps)

2. HTTP Probe

containers:
  - name: app
    image: myapp:1.0
    livenessProbe:
      httpGet:
        path: /healthz
        port: 8080
      initialDelaySeconds: 15    # Đợi 15s sau khi start
      periodSeconds: 10          # Check mỗi 10s
      failureThreshold: 3        # 3 lần fail thì restart
    readinessProbe:
      httpGet:
        path: /ready
        port: 8080
      initialDelaySeconds: 5
      periodSeconds: 5

3. TCP Probe

livenessProbe:
  tcpSocket:
    port: 3306         # MySQL port
  initialDelaySeconds: 15
  periodSeconds: 10

4. Command Probe

livenessProbe:
  exec:
    command:
      - cat
      - /tmp/healthy
  initialDelaySeconds: 5
  periodSeconds: 5

5. Startup Probe

# Cho slow-starting apps
startupProbe:
  httpGet:
    path: /healthz
    port: 8080
  failureThreshold: 30
  periodSeconds: 10        # 30 * 10 = 300s = 5 phút để start
💡 Startup probe: Khi app cần thời gian warmup (JVM, load data...), dùng startupProbe để tránh liveness kill sớm.

📝 Tóm Tắt