/ratelimit

Demo of Ratelimiting in Kubernetes using Istio

Primary LanguageJava

Getting Started

Simple Application to demonstrate Ratelimit using Istio

Build the Image

./gradlew clean build  
docker build -t hello-istio:1.0 .  
docker run --rm -p 8080:8080  hello-istio:1.0 
curl  http://localhost:8080/hello ( in other window ) 

Prepare Minikube

minikube start

minikube addons enable istio-provisioner
minikube addons enable istio

 kubectl get pod -n istio-system
 

Deploy in K8s


minikube image load hello-istio:1.0 

cd deployment 
kubectl apply -f deployment.yaml 

kubectl get pods

minikube tunnel
kubectl apply -f service.yaml 

Now you should be able to check k8s service
curl  http://localhost:8080/hello

Test without Rate limit using Postman

postman-collection

postman-runner

Create a Collection say "Containers" with just one Request for http://localhost:8080/hello

Test add this script

pm.test("Status code is 200", function () {
    pm.response.to.have.status(200);
});

Its successful when the response is 200 Run the test with 20 request and validate if all are successful

Apply Envoy filter

kubectl label namespace default istio-injection=enabled
kubectl apply -f envoyfilter.yaml
kubectl exec -it podname -c istio-proxy -- pilot-agent request GET config_dump

Test Ratelimit

kubectl apply -f envoyfilter.yaml

before-ratelimit

Test With Rate limit

Run the test with 20 request and validate only 10 of them have succeeded after-ratelimit

Clean up


kubectl delete deployment helloistio
kubectl delete service helloistio-service
minikube stop 
Also close the minikube tunnel