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
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
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.