nginx/docker-nginx-unprivileged

Pack and run Vue Application based on nginx-unprivileged in Kubernetes

Closed this issue · 3 comments

Describe the bug

A clear and concise description of what the bug is.

I have pack and run the image for Vue application in my local machine, the container is able to run as expected. But when deploy to kubernetes, the pod could not be startup due to this issue

To reproduce

Steps to reproduce the behavior:

nginx.conf as below:

worker_processes  1;
error_log  /var/log/nginx/error.log warn;
pid        /tmp/nginx.pid;
events {
  worker_connections  1024;
}
http {
  include       /etc/nginx/mime.types;
  default_type  application/octet-stream;
  log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                    '$status $body_bytes_sent "$http_referer" '
                    '"$http_user_agent" "$http_x_forwarded_for"';
  access_log  /var/log/nginx/access.log  main;
  sendfile        on;
  keepalive_timeout  65;
  server {
    listen       80;
    server_name  localhost;
    large_client_header_buffers 4 32k;
    client_header_buffer_size 32k;

    location / {
      root   /app/spa;
      index  index.html;
      try_files $uri $uri/ /index.html;
    }
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
      root   /usr/share/nginx/html;
    }
  }
}
  1. Build and Pack Vue Application with NodeJs image and Nginx-unprivilege image
  2. Deploy to kubernetes cluster
  3. See errors below appeared:

│ service-admin-ui 2024/06/13 10:19:24 [emerg] 1#1: bind() to 0.0.0.0:80 failed (13: Permission denied)
│ service-admin-ui nginx: [emerg] bind() to 0.0.0.0:80 failed (13: Permission denied)

Expected behavior

Pod should be up and healthy in Kubernetes CLuster

Your environment

  • Docker CLI version 26.1.1
  • nginxinc/nginx-unprivileged:bookworm-perl
  • Kubernetes

Kindly provides advices on how could I run it in Kubernetes, thanks

Hey @Bryson-Tai! Depending on your cluster settings you might not be able to bind to port 80 since it's historically considered to be a restricted port. Newer versions of Docker let you side step this restriction, but your cluster settings might still be set to have that port as restricted. Can you try using port 8080?

Ahh, is it change the port in server section in the nginx config to 8080? As below

worker_processes  1;
error_log  /var/log/nginx/error.log warn;
pid        /tmp/nginx.pid;
events {
  worker_connections  1024;
}
http {
  include       /etc/nginx/mime.types;
  default_type  application/octet-stream;
  log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                    '$status $body_bytes_sent "$http_referer" '
                    '"$http_user_agent" "$http_x_forwarded_for"';
  access_log  /var/log/nginx/access.log  main;
  sendfile        on;
  keepalive_timeout  65;
  server {
    listen       8080;
    server_name  localhost;
    large_client_header_buffers 4 32k;
    client_header_buffer_size 32k;

    location / {
      root   /app/spa;
      index  index.html;
      try_files $uri $uri/ /index.html;
    }
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
      root   /usr/share/nginx/html;
    }
  }
}

Yup! You might also then need to change which port gets exposed to your system on the cluster.