<p>I was trying to deploy a service to a Kubernetes cluster and first got the following error: </p>

<p><code>Error: container has runAsNonRoot and image will run as root</code></p>

<p>After some googling, I found out that there is a Pod Security Policy which doesn't allow me to run images as root, as suggested in the error.</p>

<p>I found out that adding the following securityContext configuration in my deployment definition would maybe solve my problem:</p>

<pre><code>spec:
  securityContext:
     runAsUser: [uID]
     fsGroup: [fsID]
</code></pre>

<p>I couldn't find a way though to get the user id for a given username. Is it possible using kubectl? Or do I have to somehow assign my own userId/groupId?</p>

<p>As an example, let's say I am using the minikube context:</p>

<pre><code>- context:
    cluster: minikube
    user: minikube
  name: minikube
current-context: minikube
kind: Config
preferences: {}
users:
- name: minikube
  user:
    client-certificate: C:\...\client.crt
    client-key: C:\...\client.key
</code></pre>

<p>Thanks!</p>

DeiAndrei
<blockquote>
  <p>I couldn't find a way though to get the user id for a given username. Is it possible using kubectl? Or do I have to somehow assign my own userId/groupId?</p>
</blockquote>

<p>You can run <code>id</code> command on your deployment something like <code>kubectl exec -it &lt;&lt;pod name&gt;&gt; -- sh</code> to see the user, group id for the said username, in this case, the current user context.</p>
