* SonarQube ** Required software - Helm: v3.13.2-linux-amd64 - Kubernetes ($ kubectl version): - Client Version: v1.28.4 - Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3 - Server Version: v1.28.4 - OS: Red Hat Enterprise Linux Server release 7.9 (Maipo) - Kernel: 3.10.0-1160.102.1.el7.x86_64 - Helm chart: sonarqube-8.0.3_2010 - SonarQube (installed using Helm chart): 9.9.3 (LTS) ** Networking - Service port accessible on the node: 3050 ** Prerequisites The following Kubernetes (Linux) node configuration is required for SonarQube to function correctly: 1. For elastic search: $ echo -e 'vm.max_map_count=524288\nfs.file-max=131072' | sudo tee /etc/sysctl.d/sonarqube.conf $ echo -e 'root - nofile 131072\nroot - nproc 8192' | sudo tee /etc/security/limits.d/sonarqube.conf $ sudo sysctl --system $ sudo su -c 'ulimit -n 131072' $ sudo su -c 'ulimit -u 8192' 2. In case of elastic-search number of files error, add the following line to /etc/systemd/system/multi-user.target.wants/containerd.service under the [Unit] section: - LimitNOFILE=infinity 3. In Kubernetes, local-storage storage class should be default. If it isn't then PVs may not bind to the PVC. To fix this, run: $ kubectl patch storageclass local-storage -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}' ** Docker build-image container 1. Build the build-image container using files/Dockerfile and upload it to the container registry, either DockerHub or local registry. 2. Contents of the container: 1. Ubuntu 20.04 2. Node: v18 3. Java: OpenJDK 17 4. SonarScanner java client: 5.0.1.3006 5. Google Chrome: 119 ** Template generation using Helm 1. helm repo add sonarqube https://SonarSource.github.io/helm-chart-sonarqube 2. helm repo update 3. kubectl create namespace sonarqube 4. helm show values --version ~8 sonarqube/sonarqube > values_orig.yaml 5. If the file values.yaml doesn't exist: - cp -n values_orig.yaml values.yaml 6. Modify values.yaml for required configuration. - To see the configuration differences between the original and the modified version of values.yaml, do: $ diff -u values_orig.yaml values.yaml 7. helm template -f values.yaml -n sonarqube --version ~8 sonarqube sonarqube/sonarqube > sonarqube_template_orig.yaml 8. In the current setup, sonarqube_template_orig.yaml is templatized into sonarqube_template.yaml.j2 by modifying certain variables. See constants.in for variables that have been templatized. - Variables inside sonarqube_template.yaml.j2 are replaced with values stored inside `constants.in` and `../global-constants.in` files, and then saved into sonarqube_template.yaml by running the ./setup_template.sh script. - To view the differences between the original template (sonarqube_template_orig.yaml) and the generated template (sonarqube_template.yaml) run the script using the `online` argument: $ ./setup_template.sh online 9. Modify sonarqube_template.yaml.j2 to modify the Persistent Volume (PV) properties, and constants.in for modifying the PV host path and size. ** SonarQube Kubernetes setup 1. mkdir -p /var/sonarqube/pg_data; cd /var/sonarcube 2. Copy all the files from the sonarqube tar.gz file in the current directory (tar xf ~/sonarqube_xxx.tar.gz). 3. Follow the steps below for offline (client-site) installation: - Upload 'jmx_prometheus_javaagent.jar' and 'sonar-flutter-plugin-0.5.0.jar' to the local file server. - Upload the following images to the local private container registry: 1. postgresql:11.14.0-debian-10-r22 2. busybox:1.32 3. curl:7.76.1 4. sonarqube:9.9.3-community 5. build-image:0.3 - Modify these two variables in `constants.in` file: - LOCAL_REGISTRY: Put in the correct URL of local container registry. - LOCAL_DOWNLOAD_REPO: Put in the correct URL of the local file server. 4. Run setup_template.sh: - If at client-site, run: `./setup_template.sh offline` - If on EC2 server, run: `./setup_template.sh online` 5. kubectl create namespace sonarqube 6. kubectl apply -f sonarqube_template.yaml ** SonarQube initialization 1. Open SQ URL: `$ kubectl get service -n sonarqube | grep sonarqube-sonarqube` - Port: 3050 2. Set new password to: 9YesakuZOVEjS4MyJ 3. Open /account/security 4. Generate Tokens: - Name: sonarqube-k8s-global - Type: Global Analysis Token - Expires in: 1 year - Token looks like: sqa_6b8439d64c9204f1f7e75502ddb231747e68e46b - Copy this token, will be used in SonarQube and Jenkins later.