Installing sonarqube on Openshift

Must-share information (formatted with Markdown):

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
    docker image sonarqube:v1.0.14

  • how is SonarQube deployed: zip, Docker, Helm
    Helm

  • what are you trying to achieve
    Install SonarQube on Single Node Openshift.

  • what have you tried so far to achieve this
    I am installing sonarqube on SNO cluster with Helm. Below is the config for Statefulset of sonarqube

spec:
  replicas: 1
  serviceName: sonarqube
  selector:
    matchLabels:
      app: sonarqube
  template:
    metadata:
      labels:
        app: sonarqube
    spec:
      containers:
      - env:
        - name: SONAR_JDBC_URL
          valueFrom:
            secretKeyRef:
              key: jdbc-uri
              name: {{ .Values.postgres.auth.existingSecret }}
        - name: SONAR_JDBC_USERNAME
          valueFrom:
            secretKeyRef:
              key: user
              name: {{ .Values.postgres.auth.existingSecret }}
        - name: SONAR_JDBC_PASSWORD
          valueFrom:
            secretKeyRef:
              key: password
              name: {{ .Values.postgres.auth.existingSecret }}
        - name: SONAR_FORCEAUTHENTICATION
          value: "false"
        - name: LDAP_CONTEXTFACTORYCLASS
          value: com.sun.jndi.ldap.LdapCtxFactory
        - name: SONAR_AUTHENTICATOR_CREATEUSERS
          value: "false"
        - name: SONAR_SEARCH_JAVAADDITIONALOPTS
          value: '-Dnode.store.allow_mmap=false'
        - name: SONAR_LOG_LEVEL
          value: "TRACE"
        imagePullPolicy: IfNotPresent
        image: docker.io/xxxxx/sonarqube:v1.0.14
        livenessProbe:
          failureThreshold: 3
          httpGet:
            path: /
            port: 9000
            scheme: HTTP
          initialDelaySeconds: 45
          periodSeconds: 10
          successThreshold: 1
          timeoutSeconds: 1
        name: sonarqube
        ports:
        - containerPort: 9000
          protocol: TCP
        readinessProbe:
          failureThreshold: 3
          httpGet:
            path: /
            port: 9000
            scheme: HTTP
          initialDelaySeconds: 10
          periodSeconds: 10
          successThreshold: 1
          timeoutSeconds: 1
        resources:
          requests:
            memory: 1000Mi
            cpu: 100m
          limits:
            memory: 5000Mi
            cpu: 800m
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
        volumeMounts:
        - mountPath: /opt/sonarqube/data
          name: sonarqube-data
        - mountPath: /opt/sonarqube/conf/tls.crt
          name: oauth-cert
          subPath: tls.crt
        - mountPath: /opt/sonarqube/conf/sonar.properties
          name: properties
          subPath: sonar.properties
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      serviceAccount: sonarqube
      serviceAccountName: sonarqube
      terminationGracePeriodSeconds: 30
      volumes:
      - name: oauth-cert
        secret:
          secretName: openshift-oauth-proxy-tls
      - name: properties
        configMap:
          name: sonarqube-properties
  volumeClaimTemplates:
  - metadata:
      name: sonarqube-data
    spec:
      accessModes: [ "ReadWriteOnce" ]
      resources:
        requests:
          storage: "5Gi"

Pods won’t go into ready state. With TRACE log level, following is the error log.

12:38:26.298 [main] WARN org.sonar.process.ConfigurationUtils - Referencing environment variables in configuration is deprecated and will be removed in a future version of SonarQube. You should stop using 'https://${env:KUBERNETES_SERVICE_HOST}:${env:KUBERNETES_SERVICE_PORT}/' in your configuration and use the 'KUBERNETES_SERVICE' environment variable instead.
12:38:26.318 [main] WARN org.sonar.process.ConfigurationUtils - Referencing environment variables in configuration is deprecated and will be removed in a future version of SonarQube. You should stop using 'https://${env:KUBERNETES_SERVICE_HOST}:${env:KUBERNETES_SERVICE_PORT}/' in your configuration and use the 'KUBERNETES_SERVICE' environment variable instead.
2023.03.06 12:38:27 INFO  app[][o.s.a.AppFileSystem] Cleaning or creating temp directory /opt/sonarqube/temp
2023.03.06 12:38:27 DEBUG app[][o.s.a.NodeLifecycle] main tryToMoveTo from INIT to STARTING => true
2023.03.06 12:38:27 DEBUG app[][o.s.a.p.ManagedProcessLifecycle] main tryToMoveTo es from INIT to STARTING => true
2023.03.06 12:38:27 INFO  app[][o.s.a.es.EsSettings] Elasticsearch listening on [HTTP: 127.0.0.1:9001, TCP: 127.0.0.1:41431]
2023.03.06 12:38:27 INFO  app[][o.s.a.ProcessLauncherImpl] Launch process[[key='es', ipcIndex=1, logFilenamePrefix=es]] from [/opt/sonarqube/elasticsearch]: /opt/sonarqube/elasticsearch/bin/elasticsearch
2023.03.06 12:38:27 DEBUG app[][o.s.a.p.ManagedProcessLifecycle] main tryToMoveTo es from STARTING to STARTED => true
2023.03.06 12:38:27 INFO  app[][o.s.a.SchedulerImpl] Waiting for Elasticsearch to be up and running
2023.03.06 12:38:27 DEBUG app[][o.s.a.e.EsConnectorImpl] Connected to Elasticsearch node: [127.0.0.1:9001]
2023.03.06 12:39:40 DEBUG app[][o.a.h.i.n.c.MainClientExec] [exchange: 1] start execution
2023.03.06 12:39:40 DEBUG app[][o.a.h.c.p.RequestAddCookies] CookieSpec selected: default
2023.03.06 12:39:40 DEBUG app[][o.a.h.c.p.RequestAuthCache] Re-using cached 'basic' auth scheme for http://127.0.0.1:9001
2023.03.06 12:39:40 DEBUG app[][o.a.h.c.p.RequestAuthCache] No credentials for preemptive authentication
2023.03.06 12:39:40 DEBUG app[][o.a.h.i.n.c.InternalHttpAsyncClient] [exchange: 1] Request connection for {}->http://127.0.0.1:9001
2023.03.06 12:39:40 DEBUG app[][o.a.h.i.n.c.PoolingNHttpClientConnectionManager] Connection request: [route: {}->http://127.0.0.1:9001][total kept alive: 0; route allocated: 0 of 10; total allocated: 0 of 30]
2023.03.06 12:39:40 DEBUG app[][o.a.h.i.n.c.PoolingNHttpClientConnectionManager] Connection request failed
java.net.ConnectException: Connection refused
	at java.base/sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
	at java.base/sun.nio.ch.SocketChannelImpl.finishConnect(Unknown Source)
	at org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor.processEvent(DefaultConnectingIOReactor.java:174)
	at org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor.processEvents(DefaultConnectingIOReactor.java:148)
	at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor.execute(AbstractMultiworkerIOReactor.java:351)
	at org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager.execute(PoolingNHttpClientConnectionManager.java:221)
	at org.apache.http.impl.nio.client.CloseableHttpAsyncClientBase$1.run(CloseableHttpAsyncClientBase.java:64)
	at java.base/java.lang.Thread.run(Unknown Source)

Please help!

Hi @Bilal_Bokharee,

sonarqube:v1.0.14 is eigher wrong or very out of date. The current release of sonarqube is 9.9 and if you are starting from scratch it might make sense to start from a recent version :sweat_smile:

Please try with a newer version and on openshift especially take care that your nodes can fulfill the needed requirements as stated in the docs: Prerequisites and overview

If you are installing with Helm, there should be a init container that tries to do that for you. Are you using the official Helm chart? The sts you posted seems odd to me as it would not belong to the sonarqube chart (see here: helm-chart-sonarqube/charts/sonarqube at master · SonarSource/helm-chart-sonarqube · GitHub)

2 Likes