instalacion
title: Instalación description: "GuÃa para la instalación de Sonarqube, incluyendo configuraciones para Docker Compose y Kubernetes." slug: instalacion-sonarqube
Docker Compose​
Sonarqube se puede desplegar fácilmente utilizando Docker Compose. A continuación se muestra un ejemplo de archivo docker-compose.yml
que puedes utilizar:
Crea un archivo .env en la raÃz del proyecto con el siguiente contenido, adaptando los valores a tus necesidades:
POSTGRES_USER=sonarqube
POSTGRES_PASSWORD=sonarqube
POSTGRES_DB=sonarqube
POSTGRES_HOST=postgresql
SONAR_JDBC_URL=jdbc:postgresql://postgresql:5432/sonarqube
SONAR_JDBC_USERNAME=sonarqube
SONAR_JDBC_PASSWORD=sonarqube
Crear la red para conectar Dependency-Track con Traefik:
docker network create dtrack
A continuación, crea el archivo docker-compose.yml
que define los servicios necesarios:
services:
postgresql:
image: postgres:15
container_name: sonarqube_postgresql
environment:
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: ${POSTGRES_DB}
volumes:
- ./postgresql/data:/var/lib/postgresql/data
networks:
- sonarqube_network
restart: unless-stopped
sonarqube:
image: sonarqube:25.5.0.107428-community
container_name: sonarqube
depends_on:
- postgresql
environment:
SONAR_JDBC_URL: ${SONAR_JDBC_URL}
SONAR_JDBC_USERNAME: ${SONAR_JDBC_USERNAME}
SONAR_JDBC_PASSWORD: ${SONAR_JDBC_PASSWORD}
labels:
- "traefik.enable=true"
- "traefik.http.routers.sonar.rule=Host(`sonar.opensecdevops.com`)"
- "traefik.http.routers.sonar.entrypoints=websecure"
- "traefik.http.routers.sonar.tls=true"
- "traefik.http.routers.sonar.tls.certresolver=le"
- "traefik.http.services.sonar.loadbalancer.server.port=9000"
volumes:
- ./sonarqube/data:/opt/sonarqube/data
- ./sonarqube/logs:/opt/sonarqube/logs
- ./sonarqube/extensions:/opt/sonarqube/extensions
networks:
- sonarqube_network
ulimits:
nofile:
soft: 65536
hard: 65536
restart: unless-stopped
networks:
sonarqube_network:
external: true
Iniciar los contenedores:
docker-compose up -d
Kubernetes​
To proceed with the installation of Sonarqube on our platform as with other tools we first need to clone the Sonarqube repository, so we can see the values we want to use in our deployment.
Repo​
https://github.com/SonarSource/helm-chart-sonarqube.git
We add the helm repository and upgrade
helm repo add sonarqube https://SonarSource.github.io/helm-chart-sonarqube
helm repo update
We can clone the git mentioned above and copy the values.yaml found in the following path.
cd helm-chart-sonarqube/charts/sonarqube/
And we will proceed to copy or modify the values.yaml. In this file we must have the following parameters.
ingress:
enabled: true
hosts:
- name: sonar.opensecdevops.com
path: "/"
# This property allows for reports up to a certain size to be uploaded to SonarQube
annotations:
kubernetes.io/ingress.class: appsec-nginx
nginx.ingress.kubernetes.io/proxy-body-size: "64m"
# Set the ingressClassName on the ingress record
ingressClassName: appsec-nginx
tls:
# Secrets must be manually created in the namespace. To generate a self-signed certificate (and private key) and then create the secret in the cluster please refer to official documentation available at https://kubernetes.github.io/ingress-nginx/user-guide/tls/#tls-secrets
- secretName: SECRET_CERT
# hosts:
# - chart-example.local
prometheusExporter:
enabled: false
config:
rules:
- pattern: ".*"
postgresql:
# Enable to deploy the bitnami PostgreSQL chart
enabled: true
persistence:
enabled: true
accessMode: ReadWriteOnce
size: 10Gi
we proceed to the installation with the helm
Helm​
helm upgrade --install -n sonar sonarqube -f values.yaml sonarqube/sonarqube --create-namespace
Detalles del comando anterior:
--install
: Instala si no existe, actualiza si ya está instalado.--create-namespace
: Crea el namespace si no existe.-f values.yaml
: Especifica el archivo de configuración personalizado.-n sonar
: Indica el namespace de despliegue.