gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 00:34:47 31 4
gpt4 key购买 nike

我在 Azure Kubernetes 服务 (AKS) 上部署了 Postgresql。效果很好。但是,当我使用 kubectl exec -it pod_name bash 登录 pod 时,它会自动使用“postgres”用户登录,并且我无法切换到“root” ”用户。

如果我能够使用 ssh 登录 Kubernetes 节点,我可以使用 docker exec -it -u root image_id 并使用“root”用户登录,但作为我知道这在 Azure 上是不可能的。

如何以 AKS 上的“root”用户身份登录 Pod?

谢谢!

最佳答案

您可以添加 pod securityContext。您可以在其中设置 root 用户的UID 0。默认情况下,Pod 将以 root 用户身份运行。 Ref

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

或者,如果您只想以 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

关于azure - 如何以 root 用户身份登录 Azure Kubernetes pod,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68019126/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com