<p>I deployed Postgresql on Azure Kubernetes Service (AKS). It works fine.
But when I login to the pod with <code>kubectl exec -it pod_name bash</code>, it's automatically login with &quot;<strong>postgres</strong>&quot; user and I can't switch to the &quot;<strong>root</strong>&quot; user.</p>
<p>If I could able to login Kubernetes' nodes with ssh, I could use <code>docker exec -it -u root image_id</code> and login with &quot;<strong>root</strong>&quot; user, but as I know it's not possible on Azure.</p>
<p>How can I login to the pods as &quot;root&quot; user on AKS?</p>
<p>Thanks!</p>

<p>You can add pod <code>securityContext</code>. where you can set the <code>UID 0</code> which is for root user. By default then, The Pod will run as root user. <a href="https://kubernetes.io/docs/tasks/configure-pod-container/security-context/#set-the-security-context-for-a-pod" rel="nofollow noreferrer">Ref</a></p>
<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: demo-pod
spec:
  securityContext:
    runAsUser: 0
</code></pre>
<p>Or, If you want to run just the postgres container of your pod as root then you need to use container's security context.</p>
<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: security-context-demo-2
spec:
  containers:
  - name: postgres
    image: postgres:13.2
    securityContext:
      runAsUser: 0
      Privileged: true

</code></pre>
