You can use the nginx ingress delay traffic action to delay all traffic to a specific HTTP path / HTTP Method / HTTP Headers in the ingress controller for a given time. This is useful for testing how your application behaves when specific endpoints are slowly reachable.
Requirements
Important: This action has two main requirements:
1. Enable Snippets on NGINX Ingress Controller
Snippets must be enabled on your NGINX Ingress Controller. This can be done by:
Adding --enable-snippets to the controller arguments
Or setting the enable-snippets ConfigMap option to true
Or for NGINX Ingress Operator: kubectl patch NginxIngress nginxingress-controller -n nginx-ingress --type=merge -p '{"spec":{"controller":{"enableSnippets":true}}}'
2. Install Custom NGINX Module
This action requires a custom NGINX module (ngx_steadybit_sleep_module) to be installed in your NGINX Ingress Controller. The module provides the sb_sleep_ms directive that enables artificial delays in HTTP request processing.
The module must be:
Built and installed in your NGINX Ingress Controller image
Loaded in the nginx.conf via one of these methods:
Add load_module modules/ngx_steadybit_sleep_module.so; directly to nginx.conf
Or use ConfigMap: kubectl patch configmap nginxingress-controller-nginx-ingress -n nginx-ingress --type=merge -p '{"data":{"main-snippets":"load_module /usr/lib/nginx/modules/ngx_steadybit_sleep_module.so;"}}'
Compatible with your NGINX Ingress Controller version
Understand how your services behave under network latency
Test application resilience under slow network conditions
Simulate specific endpoint performance issues
Usage
You can not apply multiple delay actions to the same ingress resource at the same time.
You can not apply the nginx delay and block actions to the same ingress resource at the same time.
Rollback
The annotation made to the ingress resource will be removed automatically after the action is finished. If you want to rollback manually, you can look for the annotation nginx.ingress.kubernetes.io/configuration-snippet (or nginx.org/server-snippets for Enterprise NGINX) in the ingress resource and remove the parts that are surrounded by # BEGIN STEADYBIT - and # END STEADYBIT -. The steadybit parts in the annotation will be removed automatically after the action is finished.
Parameters
Path Pattern, HTTP Method, and HTTP Headers are optional parameters. If you do not set them, nothing will be delayed. If you set them, all requests that match the path pattern, HTTP method, and HTTP headers will be delayed.
Name
Required
Description
Duration
true
How long should the traffic be affected?
Delay
true
The delay to apply to the path in milliseconds.
Path Pattern
false
A regex pattern to match the paths to delay.
HTTP Method
false
A http method to match the requests to delay. * is used as not set.
HTTP Headers
false
A list of HTTP headers to match the requests to delay. Value is a regex pattern. If multiple headers are set, all of them must match.