diff --git a/examples/customization/README.md b/examples/customization/README.md index 2dad3ac04d..78871197b0 100644 --- a/examples/customization/README.md +++ b/examples/customization/README.md @@ -40,6 +40,7 @@ The table below summarizes some of the options. More options (extensions) are av | `nginx.org/listen-ports` | N/A | Configures HTTP ports that NGINX will listen on. | `[80]` | | `nginx.org/listen-ports-ssl` | N/A | Configures HTTPS ports that NGINX will listen on. | `[443]` | | N/A | `worker-processes` | Sets the value of the [worker_processes](http://nginx.org/en/docs/ngx_core_module.html#worker_processes) directive. | `auto` | +| N/A | `worker-rlimit-nofile` | Sets the value of the [worker_rlimit_nofile](http://nginx.org/en/docs/ngx_core_module.html#worker_rlimit_nofile) directive. | N/A | | N/A | `worker-connections` | Sets the value of the [worker_connections](http://nginx.org/en/docs/ngx_core_module.html#worker_connections) directive. | `1024` | | N/A | `worker-cpu-affinity` | Sets the value of the [worker_cpu_affinity](http://nginx.org/en/docs/ngx_core_module.html#worker_cpu_affinity) directive. | N/A | | N/A | `worker-shutdown-timeout` | Sets the value of the [worker_shutdown_timeout](http://nginx.org/en/docs/ngx_core_module.html#worker_shutdown_timeout) directive. | N/A | diff --git a/examples/customization/nginx-config.yaml b/examples/customization/nginx-config.yaml index 3a27316caf..18b06cdc35 100644 --- a/examples/customization/nginx-config.yaml +++ b/examples/customization/nginx-config.yaml @@ -48,6 +48,7 @@ data: proxy_temp_path /var/nginx/proxy_temp; charset koi8-r; worker-processes: "1" # default is "auto". Sets the value of the worker_processes directive. See http://nginx.org/en/docs/ngx_core_module.html#worker_processes + worker-rlimit-nofile: "65536" # No default. Sets the value of the worker_rlimit_nofile directive. See http://nginx.org/en/docs/ngx_core_module.html#worker_rlimit_nofile worker-connections: "10240" # default is "1024". Sets the value of the worker_connections directive. See http://nginx.org/en/docs/ngx_core_module.html#worker_connections worker-cpu-affinity: "auto" # No default. Sets the value of the worker_cpu_affinity directive. See http://nginx.org/en/docs/ngx_core_module.html#worker_cpu_affinity worker-shutdown-timeout: "5m" # No default. Sets the value of the worker_shutdown_timeout directive. See http://nginx.org/en/docs/ngx_core_module.html#worker_shutdown_timeout diff --git a/nginx-controller/controller/controller.go b/nginx-controller/controller/controller.go index a2e46831e6..6cac1cd356 100644 --- a/nginx-controller/controller/controller.go +++ b/nginx-controller/controller/controller.go @@ -598,6 +598,9 @@ func (lbc *LoadBalancerController) syncCfgm(task Task) { if workerConnections, exists := cfgm.Data["worker-connections"]; exists { cfg.MainWorkerConnections = workerConnections } + if workerRlimitNofile, exists := cfgm.Data["worker-rlimit-nofile"]; exists { + cfg.MainWorkerRlimitNofile = workerRlimitNofile + } if keepalive, exists, err := nginx.GetMapKeyAsInt(cfgm.Data, "keepalive", cfgm); exists { if err != nil { glog.Error(err) diff --git a/nginx-controller/nginx/config.go b/nginx-controller/nginx/config.go index 343c931ffe..5209c19ff3 100644 --- a/nginx-controller/nginx/config.go +++ b/nginx-controller/nginx/config.go @@ -31,6 +31,7 @@ type Config struct { MainWorkerCPUAffinity string MainWorkerShutdownTimeout string MainWorkerConnections string + MainWorkerRlimitNofile string Keepalive int64 // http://nginx.org/en/docs/http/ngx_http_realip_module.html diff --git a/nginx-controller/nginx/configurator.go b/nginx-controller/nginx/configurator.go index 86c4f929ed..709ecadf9d 100644 --- a/nginx-controller/nginx/configurator.go +++ b/nginx-controller/nginx/configurator.go @@ -710,6 +710,7 @@ func (cnf *Configurator) UpdateConfig(config *Config, ingExes []*IngressEx) erro WorkerCPUAffinity: config.MainWorkerCPUAffinity, WorkerShutdownTimeout: config.MainWorkerShutdownTimeout, WorkerConnections: config.MainWorkerConnections, + WorkerRlimitNofile: config.MainWorkerRlimitNofile, } cnf.nginx.UpdateMainConfigFile(mainCfg) diff --git a/nginx-controller/nginx/nginx.go b/nginx-controller/nginx/nginx.go index eb338efd15..8127300590 100644 --- a/nginx-controller/nginx/nginx.go +++ b/nginx-controller/nginx/nginx.go @@ -120,6 +120,7 @@ type NginxMainConfig struct { WorkerCPUAffinity string WorkerShutdownTimeout string WorkerConnections string + WorkerRlimitNofile string } // NewUpstreamWithDefaultServer creates an upstream with the default server. diff --git a/nginx-controller/nginx/templates/nginx-plus.tmpl b/nginx-controller/nginx/templates/nginx-plus.tmpl index 8ff346fc2a..2487ee3d58 100644 --- a/nginx-controller/nginx/templates/nginx-plus.tmpl +++ b/nginx-controller/nginx/templates/nginx-plus.tmpl @@ -1,6 +1,8 @@ user nginx; worker_processes {{.WorkerProcesses}}; +{{- if .WorkerRlimitNofile}} +worker_rlimit_nofile {{.WorkerRlimitNofile}};{{end}} {{- if .WorkerCPUAffinity}} worker_cpu_affinity {{.WorkerCPUAffinity}};{{end}} {{- if .WorkerShutdownTimeout}} diff --git a/nginx-controller/nginx/templates/nginx.tmpl b/nginx-controller/nginx/templates/nginx.tmpl index fd8c8431ed..83537dc87d 100644 --- a/nginx-controller/nginx/templates/nginx.tmpl +++ b/nginx-controller/nginx/templates/nginx.tmpl @@ -1,6 +1,8 @@ user nginx; worker_processes {{.WorkerProcesses}}; +{{- if .WorkerRlimitNofile}} +worker_rlimit_nofile {{.WorkerRlimitNofile}};{{end}} {{- if .WorkerCPUAffinity}} worker_cpu_affinity {{.WorkerCPUAffinity}};{{end}} {{- if .WorkerShutdownTimeout}} diff --git a/nginx-controller/nginx/templates/templates_test.go b/nginx-controller/nginx/templates/templates_test.go index 23306abbaa..8ccf17a006 100644 --- a/nginx-controller/nginx/templates/templates_test.go +++ b/nginx-controller/nginx/templates/templates_test.go @@ -58,6 +58,7 @@ var mainCfg = nginx.NginxMainConfig{ WorkerCPUAffinity: "auto", WorkerShutdownTimeout: "1m", WorkerConnections: "1024", + WorkerRlimitNofile: "65536", } func TestIngressForNGINXPlus(t *testing.T) {