How to access SonarQube with Kubernetes Proxy?

5/28/2018

I want to deploy SonarQube to a Kubernetes cluster. The SonarQube webapp should only be accessible via Kubernetes proxy. When I try to access the frontend with the address:

http://localhost:8001/api/v1/namespaces/sonar/services/sonar:80/proxy/sonar/

I see the sonarqube loading screen. But the webapp tries to access the api with a GET request to the address

http://localhost:8001/sonar/api/l10n/index?locale=de-DE

which is, of course, not accessible.

Is there a way to set the server base adress?

My current deployment:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: sonarqube
spec:
  replicas: 1
  template:
    metadata:
      name: sonarqube
      labels:
        name: sonarqube
    spec:
      containers:
        - image: sonarqube:latest
          args:
            - -Dsonar.web.context=/sonar
          name: sonarqube
          env:
            - name: SONARQUBE_JDBC_PASSWORD
              value: sonar
            - name: SONARQUBE_JDBC_URL
              value: jdbc:postgresql://sonar-postgres:5432/sonar
          ports:
            - containerPort: 9000
              name: sonarqube

Edit: the webapp loads the styling and favicon correctly.

My service definition:

apiVersion: v1
kind: Service
metadata:
  labels:
    name: sonar
  name: sonar
spec:
  ports:
    - name: http
      port: 80
      targetPort: 9000
      protocol: TCP
      name: sonarport
  selector:
    name: sonarqube
-- Dennis P
docker
kubernetes
sonarqube

1 Answer

5/29/2018

Kubernetes proxy is not the best way to access the SonarQube web app inside a cluster.

You can set a base URL in the sonar.core.serverBaseURL property in your sonar.properties file on the server, but I am not sure if it will help you . Anyway, it is an unstable configuration and it will break in many cases - e.g., access from another host.

I highly recommend you to use Ingress and some authentication if you want additional protection (try to check External Authentication for Nginx Ingress). Also, you can use Port Forwarding on your local machine.

-- Anton Kostenko
Source: StackOverflow