SonarQube Container Graceful Restarts

So, on a VM we had the sonar.sh available to gracefully shutdown sonarqube if needed. I tried to run the code below and then went into the sonarqube bin folder and saw that it was empty or not visible to the default user.

Windows (Powershell)

$SONARQUBE_POD_NAME=$(kubectl get pods -n sonarqube -l app=sonarqube -o jsonpath='{.items[0].metadata.name}')
kubectl exec -n sonarqube -it $SONARQUBE_POD_NAME -- bash -c "echo 'Stopping SonarQube';./bin/linux-x86-64/sonar.sh stop;echo 'Starting SonarQube';./bin/linux-x86-64/sonar.sh start"

Linux (Bash)

SONARQUBE_POD_NAME=$(kubectl get pods -n sonarqube -l app=sonarqube -o jsonpath='{.items[0].metadata.name}')
kubectl exec -n sonarqube -it $SONARQUBE_POD_NAME -- bash -c "echo 'Stopping SonarQube';./bin/linux-x86-64/sonar.sh stop;echo 'Starting SonarQube';./bin/linux-x86-64/sonar.sh start"

What is the recommended safe approach to restart the sonarqube service without corrupting data?

Hey @kirkpabk.

Sorry for the delayed response.

From the commands that you posted, I assume that you are using the official sonarqube Helm chart.

You can restart your deployment/statefulset:

❯ kubectl get po -n sonarqube
NAME                     READY   STATUS    RESTARTS   AGE
sonarqube-postgresql-0   1/1     Running   0          4m25s
sonarqube-sonarqube-0    1/1     Running   0          4m25s
❯ kubectl get sts -n sonarqube
NAME                   READY   AGE
sonarqube-postgresql   1/1     4m33s
sonarqube-sonarqube    1/1     4m33s
❯ kubectl rollout restart -n sonarqube statefulset/sonarqube-sonarqube
statefulset.apps/sonarqube-sonarqube restarted
❯ kubectl get po -n sonarqube
NAME                     READY   STATUS    RESTARTS   AGE
sonarqube-postgresql-0   1/1     Running   0          5m14s
sonarqube-sonarqube-0    0/1     Running   0          8s
❯ kubectl rollout status -n sonarqube statefulset/sonarqube-sonarqube
Waiting for 1 pods to be ready...
partitioned roll out complete: 1 new pods have been updated...
❯ kubectl get po -n sonarqube
NAME                     READY   STATUS    RESTARTS   AGE
sonarqube-postgresql-0   1/1     Running   0          7m1s
sonarqube-sonarqube-0    1/1     Running   0          115s

What is the your use-case?