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

📝 Bài 24: Logging với EFK Stack

⏱️ Thời gian: 20 phút | 📚 Độ khó: Nâng cao

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

1. EFK Stack

Component Vai trò
Elasticsearch Lưu trữ và index logs
Fluentd/Fluent Bit Thu thập logs từ pods
Kibana Visualize và search logs

2. Xem Logs Cơ Bản

# Logs của pod
kubectl logs my-pod

# Follow logs (realtime)
kubectl logs -f my-pod

# Logs của container cụ thể
kubectl logs my-pod -c my-container

# Logs của previous container (crashed)
kubectl logs my-pod --previous

# Logs với timestamps
kubectl logs my-pod --timestamps

# Logs từ deployment
kubectl logs deployment/my-deployment

3. Fluent Bit DaemonSet

# Cài Fluent Bit
helm repo add fluent https://fluent.github.io/helm-charts
helm install fluent-bit fluent/fluent-bit \
    --namespace logging --create-namespace
💡 Fluent Bit vs Fluentd:
Fluent Bit: Nhẹ hơn, ít memory
Fluentd: Nhiều plugins hơn

4. Structured Logging

// Best practice: JSON logs
{"timestamp":"2024-01-15T10:30:00Z","level":"info","message":"Request processed","requestId":"abc123","duration":45}

5. Cloud Solutions

💡 Managed Logging:
AWS: CloudWatch Container Insights
GCP: Cloud Logging (Stackdriver)
Azure: Azure Monitor
Datadog, New Relic, Splunk

📝 Tóm Tắt