<p>I am testing with securityContext but I cant start a pod when I set runAsNonRoot to true.
I use vagrant to deploy a master and two minions and ssh to the host machine as the user abdelghani :</p>
<pre><code>id $USER
uid=1001(abdelghani) gid=1001(abdelghani) groups=1001(abdelghani),27(sudo)
</code></pre>
<p>Cluster information:</p>
<p>Kubernetes version: 4.4.0-185-generic
Cloud being used: (put bare-metal if not on a public cloud)
Installation method: manual
Host OS: ubuntu16.04.6
CNI and version:
CRI and version:</p>
<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: buggypod
spec:
  containers:
  - name: container
    image: nginx
    securityContext:        
      runAsNonRoot: true
</code></pre>
<p>I do :
kubectl apply -f pod.yml
it says pod mybugypod created but when I check with :
kubectl get pods
the pod’s status is CreateContainerConfigError</p>
<p>what is it I am doing wrong?</p>

<p>Nginx service will expect a read and write permission to its configuration path (/etc/nginx) by default non root user would have that access to the path that is the reason it is failing.
You just set runAsNonRoot but you can't expect or guarantee that container will start the service as user 1001. Please try setting runAsUser explicitly to 1001 like below, this should resolve your issue.</p>
<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: buggypod
spec:
  containers:
    - name: container
      image: nginx
      securityContext:        
        runAsUser: 1001 
</code></pre>
