我正在用securityContext进行测试,但当我将runAsNonRoot设置为真时,我无法启动一个吊舱。我以用户abdelghani的身份使用迷航器部署一个主服务器和两个仆从,并将ssh部署到主机上:
id $USER
uid=1001(abdelghani) gid=1001(abdelghani) groups=1001(abdelghani),27(sudo)
集群信息:
Kubernetes版本:4.4.0-185-通用云正在使用:(裸金属,如果不是在公共云上)安装方法:手动主机OS: ubuntu16.04.6 CNI和版本: CRI和版本:
apiVersion: v1
kind: Pod
metadata:
name: buggypod
spec:
containers:
- name: container
image: nginx
securityContext:
runAsNonRoot: true
我是这样做的:库贝克尔应用-f,pod.yml,它说豆荚是我创造的,但是当我检查: kubectl得到豆荚时,豆荚的状态是CreateContainerConfigError
我做错什么了?
发布于 2020-08-13 17:39:39
我试着根据你的要求运行吊舱。失败的原因是Nginx需要修改根用户拥有的/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)
我跑的规格。
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: {}
我的建议是使用Dockerfile创建一个自定义Nginx映像,该文件还为新创建的用户创建用户并为文件夹/var/cache/nginx、/etc/nginx/conf.d .d、/var/log/nginx提供权限。以实现以非根的形式运行容器。
发布于 2020-08-13 15:50:44
默认情况下,Nginx服务将期望对其配置路径(/etc/nginx)具有读写权限,非根用户将有权访问该路径,这是其失败的原因。您只需设置runAsNonRoot,但不能期望或保证容器将以用户1001的身份启动服务。请尝试将runAsUser显式设置为1001,如下所示,这将解决您的问题。
apiVersion: v1
kind: Pod
metadata:
name: buggypod
spec:
containers:
- name: container
image: nginx
securityContext:
runAsUser: 1001
https://stackoverflow.com/questions/63397725
复制相似问题