This example demonstrates how to deploy SQL Exporter with basic authentication for the metrics endpoint, without TLS encryption.
- You need access control via username/password
- TLS is handled at infrastructure level (e.g., service mesh, ingress with TLS termination)
- Want to restrict who can access metrics
values-example.yaml- Helm values file configuring basic authsecret-auth.yaml- Complete guide for creating auth password secret (multiple methods)
Create a Kubernetes secret with plaintext password:
kubectl create secret generic sql-exporter-auth \
--from-literal=password='your-secure-password' \
--namespace=your-namespaceFor more options (External Secrets, Sealed Secrets), see secret-auth.yaml.
helm install sql-exporter ../../helm -f values-example.yaml- Basic authentication with username/password
- Password automatically hashed with bcrypt at pod startup (cost: 12)
- HTTP metrics endpoint (no TLS)
- Health probes use
tcpSocket(httpGet doesn't support auth headers) - Init container reads plaintext password and generates bcrypt hash
# Check pod status
kubectl get pods -l app.kubernetes.io/name=sql-exporter
# Test metrics endpoint (with auth)
kubectl port-forward svc/sql-exporter 9399:9399
curl -u prometheus:your-secure-password http://localhost:9399/metricsPrometheus ServiceMonitor with Basic Auth:
ServiceMonitor supports basic auth credentials only when referenced from a Kubernetes secret. You'll need to:
- Create a secret with username and password for Prometheus to use
- Configure the ServiceMonitor to reference this secret via
basicAuthfield - This is separate from the password secret used by sql-exporter itself
For production, consider using TLS + auth combination (tls-auth-dynamic example) for better security.
Security Considerations:
- Password is transmitted in plaintext (no TLS) - use only in trusted networks
- For production, strongly recommend using TLS + auth combination
- See
../tls-auth-dynamic/example for complete security
Edit values-example.yaml to:
- Change username (default:
prometheus) - Change database connection string
- Adjust bcrypt cost (higher = more secure but slower)
- Add/modify collectors
- Configure resource limits
- Init container (
httpd:alpine) runs at pod startup - Reads plaintext password from secret
- Hashes password using
htpasswdwith bcrypt - Writes
web-config.ymlwith hashed password to emptyDir - Main container mounts the generated web-config and enforces auth
You may see harmless TLS handshake EOF errors from tcpSocket probes - this is expected behavior.