<p>I'm trying to run a SonarQube pod in Openshift but it seems to be mounting the persistent volume with root as the owner.</p>

<p>How can we change this to a non-root user?
I created my persistent volume with 'hostPath'.</p>

<p>You can find some more information below:</p>

<pre><code>Caused by: java.nio.file.AccessDeniedException: /opt/sonarqube/data/es
at java.nio.file.Files.createDirectory(Files.java:674)
at java.nio.file.Files.createAndCheckIsDirectory(Files.java:781)
at java.nio.file.Files.createDirectories(Files.java:767)
at org.elasticsearch.env.NodeEnvironment.(NodeEnvironment.java:169)
at org.elasticsearch.node.Node.(Node.java:165)
... 6 common frames omitted
</code></pre>

<p>Here is the sonarqube directory screenshot</p>

<p><a href="https://i.stack.imgur.com/5Ox7i.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5Ox7i.png" alt="enter image description here"></a></p>

<p>You can set a specific <code>securityContext</code> to</p>

<ul>
<li>change the group of mounted filesystems</li>
<li>change the user a pod is run as</li>
<li>pass SELinux options.</li>
</ul>

<p><a href="https://docs.openshift.org/latest/install_config/persistent_storage/pod_security_context.html" rel="nofollow noreferrer">https://docs.openshift.org/latest/install_config/persistent_storage/pod_security_context.html</a> offers some more background.</p>

<p>This setting is done in your DeploymentConfig. The key <code>securityContext</code> should already be present. With the following, the directory should be group-writable:</p>

<pre><code>securityContext:
  fsGroup: &lt;GROUPID OF SONAR&gt;
</code></pre>
