Deploy SonarQube + PostgreSQL on Kubernetes: Code Quality Stack


Deploy an automated code quality and security analysis platform on Kubernetes using SonarQube Community Edition and PostgreSQL. This setup configures isolated subfolder database initialization, dedicated persistent storage for search indices, and Traefik Ingress routing for path-based web interface access.
| Component | Type | Port | Role |
|---|---|---|---|
| sonarqube-docker | Namespace | N/A | Provides logical isolation for all SonarQube stack resources |
| sonarqube-db-secret | Secret | N/A | Stores plain-text database credentials for PostgreSQL connection authentication |
| postgres-data-pvc | PersistentVolumeClaim | N/A | Provides 10Gi persistent storage for PostgreSQL database data |
| sonarqube-data-pvc | PersistentVolumeClaim | N/A | Provides 8Gi persistent storage for SonarQube search indices and plugins |
| sonarqube-db-service | Service | 5432 | Exposes PostgreSQL database endpoints internally to the application network |
| sonarqube-db | StatefulSet | 5432 | Runs PostgreSQL 15 with custom PGDATA subfolder initialization |
| sonarqube-service | Service | 9000 | Exposes SonarQube web UI and API endpoints internally |
| sonarqube-app | Deployment | 9000 | Runs the SonarQube Community Edition analysis server |
| sonarqube-ingress | Ingress | N/A | Routes external HTTP traffic on path /app via Traefik Ingress Controller |
External HTTP requests hitting the /app path route through the Traefik Ingress controller to sonarqube-service on port 9000. The sonarqube-app Deployment connects to sonarqube-db via sonarqube-db-service:5432 using credentials from sonarqube-db-secret. PostgreSQL stores relational data inside postgres-data-pvc under the /var/lib/postgresql/data/pgdata subfolder to prevent lost+found volume mount initialization errors. SonarQube persists project metadata, extensions, and Elasticsearch indices to sonarqube-data-pvc mounted at /opt/sonarqube/data.
vm.max_map_count set to at least 262144 for Elasticsearchvm.max_map_count set to 262144 at the OS level.sonarqube-db-secret before applying to production environments.kubectl get pods -n sonarqube-docker to confirm sonarqube-app-0 and sonarqube-db-0 pods display 1/1 in the Ready column.kubectl logs deployment/sonarqube-app -n sonarqube-docker to verify that SonarQube is operational appears in the log output./app to access the SonarQube web interface.This template provisions a fully isolated SonarQube analysis platform on Kubernetes configured with PostgreSQL database persistence, Traefik Ingress routing, and optimized storage mount settings.