You can use the nginx ingress block traffic action to block all traffic to a specific HTTP path / HTTP Method / HTTP Headers in the ingress controller by returning a specific HTTP status code. This is useful for testing how your application behaves when specific endpoints are not reachable.
Requirements
Important: 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}}}'
Use Cases
Test application resilience when specific endpoints are unavailable
Simulate partial service outages
Block specific clients identified by HTTP headers
Usage
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 blocked. If you set them, all requests that match the path pattern, HTTP method, and HTTP headers will be blocked.
Name
Required
Description
Duration
true
How long should the traffic be affected?
Status Code
true
The status code which should get returned (100-999).
Path Pattern
false
A regex pattern to match the paths to block.
HTTP Method
false
A http method to match the requests to block. * is used as not set.
HTTP Headers
false
A list of HTTP headers to match the requests to block. Value is a regex pattern. If multiple headers are set, all of them must match.