K8s by Example: Adapter Pattern
| The adapter pattern transforms an application’s interface to match a standard expected by external systems. Unlike sidecars that add features, adapters normalize existing interfaces. Use for: exposing Prometheus metrics from apps that don’t support it, converting log formats, standardizing health check endpoints. |
| adapter-redis-prometheus.yaml | |
| Redis doesn’t expose Prometheus metrics natively. The redis_exporter adapter queries Redis and exposes metrics in Prometheus format on port 9121. Prometheus scrapes the adapter, not Redis directly. | |
| The adapter container connects to Redis on localhost:6379 (shared network namespace) and translates Redis INFO command output into Prometheus metrics format. | |
| adapter-mysql-prometheus.yaml | |
| MySQL metrics adapter exposes database performance metrics (queries/sec, connections, replication lag) in Prometheus format. Requires read-only database credentials. | |
| adapter-nginx-prometheus.yaml | |
| Nginx exports basic metrics via stub_status module. The nginx-prometheus-exporter adapter parses this output and converts it to Prometheus format with proper metric names and labels. | |
| nginx-status-config.yaml | |
| Enable nginx stub_status on a separate port (8080) for the exporter to scrape. This endpoint is internal to the Pod and not exposed externally. | |
| adapter-log-format.yaml | |
| A log format adapter transforms application-specific log formats into a standardized JSON format. The adapter reads logs from a shared volume and outputs normalized JSON to stdout. | |
| adapter-health-check.yaml | |
| A health check adapter provides a standardized HTTP health endpoint for apps that don’t have one. The adapter runs queries against the app and exposes the result on a standard endpoint. | |
| terminal | |
| Verify the adapter is working by checking its metrics endpoint. Prometheus will scrape this endpoint automatically based on the annotations. The adapter translates Redis-specific data to standard metrics. | |