Abd*_*ani 5 security kubernetes
我正在使用 securityContext 进行测试,但是当我将 runAsNonRoot 设置为 true 时,我无法启动 pod。\n我使用 vagrant 以用户 abdelghani 的身份将一个 master 和两个 minion 以及 ssh 部署到主机:
\nid $USER\nuid=1001(abdelghani) gid=1001(abdelghani) groups=1001(abdelghani),27(sudo)\nRun Code Online (Sandbox Code Playgroud)\n集群信息:
\nKubernetes 版本:4.4.0-185-generic\n使用云:(不在公有云则裸机)\n安装方式:手动\n主机操作系统:ubuntu16.04.6\nCNI 及版本:\nCRI 及版本:
\napiVersion: v1\nkind: Pod\nmetadata:\n name: buggypod\nspec:\n containers:\n - name: container\n image: nginx\n securityContext: \n runAsNonRoot: true\nRun Code Online (Sandbox Code Playgroud)\n我这样做:\nkubectl apply -f pod.yml\nit 说 pod mybugypod 创建了,但是当我检查时:\nkubectl get pods\npod\xe2\x80\x99s 状态是 CreateContainerConfigError
\n我做错了什么?
\n我尝试根据您的要求运行 Pod。它失败的原因是 Nginx 需要修改 root 拥有的 /etc/ 中的某些配置,当您 runAsNonRoot 时,它会失败,因为它无法编辑 Nginx 默认配置。
这是您运行时实际遇到的错误。
10-listen-on-ipv6-by-default.sh: error: can not modify /etc/nginx/conf.d/default.conf (read-only file system?)
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
2020/08/13 17:28:55 [warn] 1#1: the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /etc/nginx/nginx.conf:2
nginx: [warn] the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /etc/nginx/nginx.conf:2
2020/08/13 17:28:55 [emerg] 1#1: mkdir() "/var/cache/nginx/client_temp" failed (13: Permission denied)
nginx: [emerg] mkdir() "/var/cache/nginx/client_temp" failed (13: Permission denied)
Run Code Online (Sandbox Code Playgroud)
我运行的规范。
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: null
labels:
run: buggypod
name: buggypod
spec:
securityContext:
runAsNonRoot: true
runAsUser: 1000
containers:
- image: nginx
name: buggypod
resources: {}
dnsPolicy: ClusterFirst
restartPolicy: Always
status: {}
Run Code Online (Sandbox Code Playgroud)
我的建议是您使用 Dockerfile 创建自定义 Nginx 映像,该映像还创建用户并为新创建的用户提供对文件夹 /var/cache/nginx、/etc/nginx/conf.d、/var/log/nginx 的权限。这样您就可以以非 Root 身份运行容器。
| 归档时间: |
|
| 查看次数: |
10311 次 |
| 最近记录: |