【问题标题】:why I am getting Read only file system error from Nginx?为什么我从 Nginx 收到只读文件系统错误?
【发布时间】:2019-08-23 22:20:27
【问题描述】:

尊敬的 K8S 社区团队,

我在部署应用程序 pod 时从 nginx 收到此错误消息。我的应用程序 angular6 应用程序托管在 nginx 服务器内,该服务器部署为 EKS 内的 docker 容器。

我将我的应用程序配置为“只读容器文件系统”,但我将“emptyDir”类型的“临时挂载”卷与只读文件系统结合使用。

所以我不确定以下错误的原因:

2019/04/02 14:11: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;
...

【问题讨论】:

  • 您好,您将它安装到/tmp,但在/var/cache/nginx/client_temp 创建文件。这是 2 个不同的位置。 /tmp 来自 emptydir 但其他是容器文件系统的一部分,它是只读的
  • 你是对的!现在我正在重定向 nginx 以在我安装的卷中创建文件: nginx.conf code .. http { client_body_temp_path /tmp 1 2; proxy_temp_path /tmp 1 2; fastcgi_temp_path /tmp 1 2; uwsgi_temp_path /tmp 1 2; scgi_temp_path /tmp 1 2; ... 服务器 { 听 0.0.0.0:80; code 但现在出现此错误:2019/04/02 15:22:43 [emerg] 1#1: bind() to 0.0.0.0:80 failed (13: Permission denied) nginx: [emerg] bind()到 0.0.0.0:80 失败(13:权限被拒绝)

标签: nginx deployment kubernetes kubernetes-helm security-context


【解决方案1】:

您的 nginx 似乎没有以 root 用户身份运行。

自发布 1.12.1-r2 以来,nginx 守护进程正在以用户 1001 的身份运行。

1.12.1-r2

nginx 容器已迁移到非 root 容器方法。以前容器以 root 用户身份运行,而 nginx 守护进程以 nginx 用户身份启动。从现在开始,容器和 nginx 守护进程都以用户 1001 运行。因此,运行 nginx 进程的用户可以写入配置文件。

这就是你无法绑定端口80的原因,必须使用端口> 1000。

你应该使用:

  ports:
   - '80:8080'
   - '443:8443'

编辑 nginx.conf 使其监听 8080 端口:

server {
        listen 0.0.0.0:8080;
        ...

或者以 root 身份运行 nginx: command: [ "/bin/bash", "-c", "sudo nginx -g 'daemon off;'" ]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多