This repository consists of two things:
-
NGINX
Dockerfileand its necessary assets for building -
NGINX
Helm ChartincludingNGINX Prometheus Exporter.
We are using nginxinc/nginx-unprivileged as a base image in order to run NGINX with non-root privileges so it's possible to run it in an Openshift cluster (as we know, Openshift does not allow running containers with root privileges).
Besides that the Dockerfile is pretty straight forward so you can check it out yourself.
-
/etc/nginx/conf.d/deafult.conf- Main server configurations. This server runs on port8080and it should process all of incoming traffic. -
/etc/nginx/conf.d/status_site.conf- This server runs on port8081and provides access to basic status data. You should use this server in order to makelivenesschecks on your application. This server should not be accessible outside the cluster.
Since we are using Open Policy Agent (aka OPA) as our gatekeeper, it's necessary to integrate NGINX with it.
- The docker image contains the
auth.jsfile, which is responsible for handling requests that require authorization but the NGINX server does not actually handle the authorization process - we commented the code section responsible for this logic.
The docker image provides default log format (/etc/nginx/log_format). It's not possible to extend the log format, so if you'd want to add/remove certain fields you have to override it.
There is also an Helm Chart for deploying this NGINX in an Openshift environment (let alone any K8S environment). Besides NGINX, this Helm Chart also deploys (on deamend) a Prometheus exporter for NGINX using nginx-prometheus-exporter. Follow the parameters below in order to configure NGINX and its Prometheus exporter as you wish.
For a detailed list of configurable values, please refer to the values.md file.
These are the main parameters you should adjust when you deploy this Helm Chart. You can find all parameters in the values.yaml file.
There's an option to dynamically add annotations to the pod. You might find it useful if you operate on different environments and need to customize your annotations. It can be done by editing the additionalPodAnnotations parameter.
There's support for instrumenting NGINX with OpenTelemetry (currently only for tracing). Simply the relevant parameters in the values.yaml file.
If you wish to override the default configuration files, you can do it by providing an external ConfigMap and supplying Volumes & VolumeMounts that'll be added to the Deployment.
In this example we override the default.conf file by creating a ConfigMap and overriding the extraVolumes, extraVolumeMounts and sidecars sections:
apiVersion: v1
kind: ConfigMap
metadata:
name: nginx-extra-configmap
data:
default.conf: {{ tpl (.Files.Get "config/default.conf") . | quote }}
And then, in the values.yaml file:
...
extraVolumes:
- name: nginx-extra-config
configMap:
name: 'nginx-extra-configmap'
extraVolumeMounts:
- name: nginx-extra-config
mountPath: "/etc/nginx/conf.d/default.conf"
subPath: default.conf
sidecars:
- name: envoy
image: "envoyproxy/envoy:v1.20.7"
volumeMounts: []
args: []
resources: {}
ports: []
...
