github.com/nginxinc/kubernetes-ingress@v1.12.5/examples-of-custom-resources/rate-limit/README.md (about) 1 # Rate Limit 2 3 In this example, we deploy a web application, configure load balancing for it via a VirtualServer, and apply a rate limit policy. 4 5 ## Prerequisites 6 7 1. Follow the [installation](https://docs.nginx.com/nginx-ingress-controller/installation/installation-with-manifests/) instructions to deploy the Ingress Controller. 8 1. Save the public IP address of the Ingress Controller into a shell variable: 9 ``` 10 $ IC_IP=XXX.YYY.ZZZ.III 11 ``` 12 1. Save the HTTP port of the Ingress Controller into a shell variable: 13 ``` 14 $ IC_HTTP_PORT=<port number> 15 ``` 16 17 ## Step 1 - Deploy a Web Application 18 19 Create the application deployment and service: 20 ``` 21 $ kubectl apply -f webapp.yaml 22 ``` 23 24 ## Step 2 - Deploy the Rate Limit Policy 25 26 In this step, we create a policy with the name `rate-limit-policy` that allows only 1 request per second coming from a single IP address. 27 28 Create the policy: 29 ``` 30 $ kubectl apply -f rate-limit.yaml 31 ``` 32 33 ## Step 3 - Configure Load Balancing 34 35 Create a VirtualServer resource for the web application: 36 ``` 37 $ kubectl apply -f virtual-server.yaml 38 ``` 39 40 Note that the VirtualServer references the policy `rate-limit-policy` created in Step 2. 41 42 ## Step 4 - Test the Configuration 43 44 Let's test the configuration. If you access the application at a rate that exceeds one request per second, NGINX will start rejecting your requests: 45 ``` 46 $ curl --resolve webapp.example.com:$IC_HTTP_PORT:$IC_IP http://webapp.example.com:$IC_HTTP_PORT/ 47 Server address: 10.8.1.19:8080 48 Server name: webapp-dc88fc766-zr7f8 49 . . . 50 51 $ curl --resolve webapp.example.com:$IC_HTTP_PORT:$IC_IP http://webapp.example.com:$IC_HTTP_PORT/ 52 <html> 53 <head><title>503 Service Temporarily Unavailable</title></head> 54 <body> 55 <center><h1>503 Service Temporarily Unavailable</h1></center> 56 <hr><center>nginx/1.19.1</center> 57 </body> 58 </html> 59 ``` 60 61 > Note: The command result is truncated for the clarity of the example.