azure - 如何以 root 用户身份登录到 Azure Kubernetes pod
问题描述
我在 Azure Kubernetes 服务 (AKS) 上部署了 Postgresql。它工作正常。但是当我使用 登录 pod 时kubectl exec -it pod_name bash
,它会自动使用“ postgres ”用户登录,我无法切换到“ root ”用户。
如果我能够使用 ssh 登录 Kubernetes 的节点,我可以使用docker exec -it -u root image_id
“ root ”用户登录,但我知道这在 Azure 上是不可能的。
如何在 AKS 上以“root”用户身份登录 pod?
谢谢!
解决方案
您可以添加 pod securityContext
。您可以在其中设置UID 0
哪个是root用户。默认情况下,Pod 将以 root 用户身份运行。参考
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
推荐阅读
- angular - 未找到模块错误无法解析角度 7
- r - 设置 ROC 的 y 值
- php - 无法访问 /en/ 子文件夹中的 index.php
- hadoop - 当端口未打开时,是否可以通过 nginx 进行端口转发?
- c - 如何修复 - 使用 getchar() 和 do-while 的意外输出
- java - 无法加载 PySpark ALS 模型
- javascript - 流:结合精确的对象类型
- python - 如何在 python 中使用 pika (RabbitMQ) 向消费者添加多处理
- android - 从谷歌播放更新后应用程序不断崩溃
- dataframe - 将 dict 中的键值对分配给 DataDrame 在 Julia 1.1 中不起作用