Grafana data source test fails with `Bad Gateway` (HTTP 502)
BeginnerTroubleshootingGrafana dashboards and data sources
Answer
Likely causes → Grafana's backend cannot reach the URL: wrong host/port, DNS failure from the Grafana pod, NetworkPolicy, or the backend is down.
Diagnose →
kubectl exec -n monitoring deploy/grafana -- wget -qO- -T 5 http://prometheus-operated:9090/-/ready
kubectl logs -n monitoring deploy/grafana | grep -i 'proxy\|datasource'
Fix → Use the in-cluster DNS name (http://prometheus-operated.monitoring.svc:9090), set access mode to Server (not Browser), and open NetworkPolicy egress.
Prevent → Provision data sources as code and check them after cluster changes.
More on Grafana dashboards and data sources
Every panel on a dashboard shows `No data`BeginnerData source test returns `Post "http://prometheus:9090/api/v1/query": dial tcp: lookup prometheus on 10.96.0.10:53: no such host`BeginnerGrafana shows `504 Gateway Timeout` on long-range queriesAdvancedGrafana behind a reverse proxy shows `If you're seeing this Grafana has failed to load its application files`BeginnerGrafana login loops back to the login page after successful OAuthIntermediateGrafana pod logs `database is locked` and dashboards fail to saveIntermediate