简体   繁体   English

如何以 root 用户身份登录 Azure Kubernetes pod

[英]How to login as root user to Azure Kubernetes pod

I deployed Postgresql on Azure Kubernetes Service (AKS).我在 Azure Kubernetes 服务 (AKS) 上部署了 Postgresql。 It works fine.它工作正常。 But when I login to the pod with kubectl exec -it pod_name bash , it's automatically login with " postgres " user and I can't switch to the " root " user.但是当我使用kubectl exec -it pod_name bash登录到 pod 时,它会自动以“ postgres ”用户登录,我无法切换到“ root ”用户。

If I could able to login Kubernetes' nodes with ssh, I could use docker exec -it -u root image_id and login with " root " user, but as I know it's not possible on Azure.如果我能够使用 ssh 登录 Kubernetes 的节点,我可以使用docker exec -it -u root image_id并使用“ root ”用户登录,但我知道这在 Azure 上是不可能的。

How can I login to the pods as "root" user on AKS?如何在 AKS 上以“root”用户身份登录到 Pod?

Thanks!谢谢!

You can add pod securityContext .您可以添加 pod securityContext where you can set the UID 0 which is for root user.您可以在其中设置 root 用户的UID 0 By default then, The Pod will run as root user.默认情况下,Pod 将以 root 用户身份运行。 Ref 参考

apiVersion: v1
kind: Pod
metadata:
  name: demo-pod
spec:
  securityContext:
    runAsUser: 0

Or, If you want to run just the postgres container of your pod as root then you need to use container's security context.或者,如果您只想以 root 身份运行 pod 的 postgres 容器,那么您需要使用容器的安全上下文。

apiVersion: v1
kind: Pod
metadata:
  name: security-context-demo-2
spec:
  containers:
  - name: postgres
    image: postgres:13.2
    securityContext:
      runAsUser: 0
      Privileged: true

Try this it helped me:试试这个它帮助了我:

Kubectl -n NAMESPACE exec --stdin --tty [POD_NAME] -- ./bin/bash Kubectl -n NAMESPACE exec --stdin --tty [POD_NAME] -- ./bin/bash

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM