Prompt
What are the best practices for monitoring Kubernetes clusters, containers, and databases in production?
Latest observation
Here are the core best practices for monitoring Kubernetes clusters, containers, and databases in production.
1) Monitor the right layers
You want visibility at multiple levels, not just “is the app up?”:
- Infrastructure: CPU, memory, disk, network, node health
- Kubernetes control plane: API server, scheduler, controller manager, etcd
- Cluster resources: nodes, pods, deployments, namespaces, ingress, services
- Containers / workloads: restarts, OOMKills, resource limits, health checks, latency
- Applications: request rate, error rate, latency, saturation, business KPIs
- Databases: query latency, connections, replication lag, locks, cache hit rate, storage
- Logs and traces: for debugging and root cause analysis
2) Use the four golden signals
For services and workloads, prioritize:
- Latency
- Traffic
- Errors
- Saturation
These are especially useful for alerting because they map to user impact.
3) Define clear SLOs and alert on symptoms, not noise
Best practice is to alert on:
- User-facing symptoms: high error rate, high latency, failed requests
- SLO burn rate: how quickly you’re consuming your error budget
- Critical infrastructure failures only when they threaten service availability
Avoid alerting on every minor spike in CPU or memory unless it affects service health.
4) Kubernetes-specific metrics to track
Cluster and node health
- Node readiness / not-ready status
- CPU, memory, disk, and network utilization
- Disk pressure, memory pressure, PID pressure
- Node reboot / eviction events
- Kubelet health
- etcd health and latency
Workload health
- Pod restarts
- CrashLoopBackOff, ImagePullBackOff, OOMKilled
- Replica availability vs desired replicas
- Deployment rollout status
- Pod pending duration
- HPA status and scaling behavior
Control plane
- API server request latency and error rate
- Scheduler queue delays
- Controller reconciliation failures
- etcd disk latency, leader changes, DB size growth
5) Container monitoring best practices
Track per-container:
- CPU and memory usage vs limits/requests
- Restarts and exit codes
- Open file descriptors
- Network I/O
- Container throttling
- Readiness/liveness probe failures
Also:
- Set sensible requests and limits
- Watch for memory leaks and CPU throttling
- Use probes carefully so they reflect real service health, not just process existence
6) Database monitoring best practices
Monitor databases from both the host and database engine perspective.
Universal DB metrics
- Query latency and throughput
- Active connections / connection pool usage
- CPU, memory, disk I/O, disk space
- Cache hit ratio
- Replication lag
- Lock waits / deadlocks
- Slow queries
- Backup success/failure
- Failover events
- Storage growth trends
Engine-specific examples
- PostgreSQL: autovacuum activity, checkpoint timing, WAL growth, replication lag, deadlocks
- MySQL/MariaDB: InnoDB buffer pool, lock waits, replication delay, slow query log
- MongoDB: replication lag, page faults, lock percentage, cache eviction
- Redis: memory fragmentation, hit rate, evictions, latency, replication health
7) Centralize logs, metrics, and traces
Use observability triads together:
- Metrics for trends and alerting
- Logs for context and debugging
- Traces for distributed request flow and latency breakdowns
Best practices:
- Use structured logging (JSON)
- Include correlation/request IDs
- Centralize collection
- Set retention policies based on compliance and operational needs
8) Alerting: keep it actionable
Good alerts are:
- Specific
- Tied to impact
- Actionable
- Prioritized by severity
Avoid:
- Duplicate alerts
- Flapping alerts
- Too many warnings
- Alerts without owners or runbooks
For each alert, define:
- What it means
- Likely causes
- Immediate steps
- Escalation path
9) Set baselines and capacity trends
Monitor trends over time:
- Resource consumption growth
- Seasonal patterns
- Capacity headroom
- Scaling effectiveness
- Database growth and storage forecasts
This helps prevent outages caused by gradual exhaustion.
10) Secure and reliable monitoring setup
- Protect monitoring endpoints and credentials
- Minimize privileged access
- Use TLS where possible
- Ensure monitoring continues during partial outages
- Run monitoring components with high availability
- Back up dashboards, alert rules, and configs
11) Build dashboards for different audiences
Create separate views for:
- SRE/ops: cluster health, alerts, saturation, incidents
- Developers: service latency, error rates, deployments
- DBAs: query performance, locks, replication, storage
- Management: availability, SLOs, incident trends
Don’t put everything on one dashboard.
12) Test alerts and monitoring regularly
- Simulate failures
- Validate alert routing
- Perform game days / chaos tests
- Verify dashboards after deployments
- Ensure logs/metrics/traces are actually useful during incidents
Recommended tooling
Common production setups include:
- Metrics: Prometheus, Grafana, Alertmanager
- Logs: Loki, Elasticsearch/OpenSearch, Fluent Bit/Fluentd
- Tracing: OpenTelemetry, Jaeger, Tempo
- Kubernetes metrics: kube-state-metrics, node-exporter, cAdvisor
- DB exporters: postgres_exporter, mysqld_exporter, mongodb_exporter, redis_exporter
Quick checklist
- Monitor nodes, pods, control plane, apps, and DBs
- Alert on symptoms and SLO burn rate
- Use logs, metrics, and traces together
- Track resource requests/limits and actual usage
- Watch database latency, replication, locks, and storage
- Keep alerts actionable and owned
- Review capacity trends regularly
- Test monitoring in failure scenarios
If you want, I can also give you:
- a sample Kubernetes monitoring dashboard layout,
- a production alert rule set, or
- a tooling stack recommendation for small/medium/large environments.