<p>I tried editing the running pod runAsUser by 1010 but i am unbale to do so, it kept running with root. Do i need to edit or delete some more tags in order to run this correctly as user 1010
HOwever, if i create  the yaml from scrtach and put the runAsUser there, its been correctly been interpreted.</p>
<p>Running Below Code gives me that the user is being run as root, however, i have mentioned it as 1010:</p>
<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: ubuntu-sleeper
  namespace: default
spec:
  securityContext:
    runAsUser: 1010
  containers:
  - command:
    - sleep
    - &quot;4800&quot;
    image: ubuntu
    imagePullPolicy: Always
    name: ubuntu
    resources: {}
    terminationMessagePath: /dev/termination-log
    terminationMessagePolicy: File
    volumeMounts:
    - mountPath: /var/run/secrets/kubernetes.io/serviceaccount
      name: default-token-v9rcc
      readOnly: true
  dnsPolicy: ClusterFirst
  enableServiceLinks: true
  nodeName: node01
  preemptionPolicy: PreemptLowerPriority
  priority: 0
  restartPolicy: Always
  schedulerName: default-scheduler
  securityContext: {}
  serviceAccount: default
  serviceAccountName: default
  terminationGracePeriodSeconds: 30
  tolerations:
  - effect: NoExecute
    key: node.kubernetes.io/not-ready
    operator: Exists
    tolerationSeconds: 300
  - effect: NoExecute
    key: node.kubernetes.io/unreachable
    operator: Exists
    tolerationSeconds: 300
  volumes:
  - name: default-token-v9rcc
    secret:
      defaultMode: 420
      secretName: default-token-v9rcc
</code></pre>
<p>runAsUser</p>
<pre><code>controlplane $ k exec ubuntu-sleeper -- whoami
root
</code></pre>
<p>Similarly, if i run the below code, it gives me that its being run by</p>
<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: ubuntu-sleeper
  namespace: default
spec:
  securityContext:
    runAsUser: 1010
  containers:
  - command:
    - sleep
    - &quot;4800&quot;
    image: ubuntu
    name: ubuntu-sleeper

</code></pre>
<hr />
<pre><code>controlplane $ k exec ubuntu-sleeper -- whoami
whoami: cannot find name for user ID 1010

</code></pre>

user190245
<p>The reason that the Pod runs as root is that the <code>securityContext</code> is listed twice in the podSpec. See lines 7 and 30 of the example file.</p>
<p>According <a href="https://github.com/kubernetes/kubernetes/issues/14791" rel="nofollow noreferrer">this issue</a> on the Kubernetes Github project, currently, the YAML and JSON parsers silently drop duplicate keys. In your case, Kubernetes is taking the second security context key, which is <code>securityContext: {}</code>.</p>
<p>It's quite frustrating, I've been there! Hope this helps. Keep an eye on that Github issue if you want to track the status of any changes to the Kubernetes YAML parser that will make detection of duplicate keys easier in the future.</p>
