Override Nginx configuration in the Traffic container
🎯 Goal: Customize the Nginx configuration used by the Traffic container in a Kubernetes scope, enabling advanced features such as WebSocket and custom headers, while preserving nullplatform metrics compatibility.
Introduction​
By default, the Kubernetes scope provided by nullplatform ships with a preconfigured Nginx setup inside the Traffic container. In some advanced scenarios, you may need to override this configuration, for example:
- Enabling WebSocket support
- Adding custom headers
- Tuning Nginx behavior for specific workloads
This tutorial walks you through creating a scope override that replaces the default nginx.conf using
a ConfigMap. You’ll then wire that configuration into the Traffic container in a safe, supported way.
Metrics shown in nullplatform are derived from the Traffic container logs. Do not modify the logging block in the Nginx configuration, or metrics may break.
What you’ll set up​
By the end of this guide, you’ll have:
- A custom Nginx configuration stored in a ConfigMap
- The Traffic container mounting that configuration
- A modified deployment workflow that renders and applies the ConfigMap
- An agent-backed scope using your customized Traffic container
Prerequisites​
- Helm installed
- A running nullplatform agent
- Access to our scopes repository
1. Start from the main scope branch​
Clone the scopes repository and make sure you are working from the main branch:
git clone https://github.com/nullplatform/scopes.git
cd scopes
git checkout main
All changes in this tutorial will be applied on top of the base Kubernetes scope.
2. Create a ConfigMap template for Nginx​
Navigate to the following directory:
k8s/templates/
Create a new file with the .yaml.tpl extension, for example:
config-maps-traffic.yaml.tpl
This template defines a ConfigMap that contains your custom nginx.conf.
Preserve the logging configuration​
Make sure your nginx.conf keeps the original logging block, as shown below:
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr [$time_local] "$request" '
'$status $request_time $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" "$quality"';
map $status $quality {
~^[23] "OK (2XX, 3XX)";
~^4 "DENIED (4XXs)";
default "ERROR (5XXs)";
}
...
}
You can extend the configuration with WebSocket support or custom headers, as long as this block remains unchanged.
🤓 Here's an example of what your file should look like: configmaps.yaml.tpl
3. Mount the ConfigMap into the Traffic container​
Open the deployment template located at:
k8s/deployment/templates/deployment.yaml.tpl
Here's where we'll reference the ConfigMap so it can be used as nginx.conf.
Add the volume definition​
Inside the spec section, add:
volumes:
- name: nginx-config
configMap:
name: nginx-config-{{ .scope.id }}-{{ .deployment.id }}
Add volume mounts to the Traffic container​
In the Traffic container definition, add:
volumeMounts:
- name: nginx-config
mountPath: /etc/nginx/nginx.conf
subPath: nginx.conf
- name: nginx-config
mountPath: /etc/nginx/conf.d/default.conf
subPath: default.conf
This ensures Nginx uses your custom configuration files at runtime.