亲爱的K8S社区团队,
当我部署我的应用程序pod时,我从nginx那里得到了这个错误消息。我的应用程序angular6应用程序托管在nginx服务器中,该服务器部署为EKS中的一个坞容器。
我的应用程序配置为“只读容器文件系统”,但我使用“emptyDir”类型的“临时挂载”卷和只读文件系统。
因此,我不确定以下错误的原因:
2019/04/02 14:29 emerg 1#1: mkdir() "/var/cache/nginx/client_temp“失败(30:只读文件系统) nginx: emerg mkdir() "/var/cache/nginx/client_temp”失败(30:只读文件系统)
我的deployment.yaml是:
...
spec:
volumes:
- name: tmp-volume
emptyDir: {}
# Pod Security Context
securityContext:
fsGroup: 2000
containers:
- name: {{ .Chart.Name }}
volumeMounts:
- mountPath: /tmp
name: tmp-volume
image: "{{ .Values.image.name }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
securityContext:
capabilities:
add:
- NET_BIND_SERVICE
drop:
- ALL
securityContext:
readOnlyRootFilesystem: true
ports:
- name: http
containerPort: 80
protocol: TCP
...nginx.conf是:
...
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Turn off the bloody buffering to temp files
proxy_buffering off;
sendfile off;
keepalive_timeout 120;
server_names_hash_bucket_size 128;
# These two should be the same or nginx will start writing
# large request bodies to temp files
client_body_buffer_size 10m;
client_max_body_size 10m;
...发布于 2019-04-16 08:49:06
您的nginx似乎不是以root用户的身份运行的。
自从发布1.12.1-r2以来,nginx守护进程就以用户1001的身份运行。
1.12.1-r2 nginx容器已经迁移到非根容器方法。以前,容器作为根用户运行,nginx守护进程作为nginx用户启动。从现在起,容器和nginx守护进程都以用户1001的身份运行。因此,运行nginx进程的用户可以写入配置文件。
这就是您无法在端口80上绑定的原因,所以必须使用端口> 1000。
你应该使用:
ports:
- '80:8080'
- '443:8443'并编辑nginx.conf,以便它在端口8080上侦听:
server {
listen 0.0.0.0:8080;
...或者将nginx作为root运行:command: [ "/bin/bash", "-c", "sudo nginx -g 'daemon off;'" ]
发布于 2022-05-07 10:51:26
正如Crou已经指出的,nginx映像维护人员切换到了非根用户方法。
这有两个含义:
您可以尝试像Crou (nginx.conf和deployment.yaml)所描述的那样更改端口。即使将NET_BIND_SERVICE功能添加到容器中,这也不一定意味着nginx流程获得了此功能。您可以尝试将功能添加到
$ sudo setcap 'cap_net_bind+p' $(which nginx)作为您的Dockerfile中的运行指令。然而,更改侦听端口通常更简单。
对于文件系统,请注意,/var/cache/nginx/不是作为卷挂载的,因此属于RootFS,它是以只读方式挂载的。解决这一问题的最简单方法是在emptyDir部分中为/var/cache/nginx/添加第二个epheremal volumes。请确保nginx用户具有读取和写入此目录的文件系统权限。只要您停留在默认位置,这通常已经由码头映像维护人员来处理。
我建议您不要切换到以根用户身份运行nginx,因为这可能会使您暴露出安全漏洞。
https://stackoverflow.com/questions/55477337
复制相似问题