zufardhiyaulhaq / istio-ratelimit-operator

Automatically create global & local rate limit in Istio, support EnvoyFilter versioning, ratelimit metrics, shadow mode, and ratelimit based on route!
MIT License
39 stars 9 forks source link

Implement RateLimitService object to automatically create external Rate Limit service #1

Closed zufardhiyaulhaq closed 3 years ago

zufardhiyaulhaq commented 3 years ago

Summary

Implement custom CRD to automatically create external rate limit service as Kubernetes deployment. Automatically configure the config map from GlobalRateLimit CRD.

How has this been tested?

Proof:

  1. Apply Global ratelimit example

    kubectl apply -f examples/global/
  2. Check Object

    
    kubectl get GlobalRateLimitConfig
    NAME                   AGE
    istio-public-gateway   3m1s

kubectl get GlobalRateLimit NAME AGE helloworld-zufardhiyaulhaq-com-bar-route 2m57s helloworld-zufardhiyaulhaq-com-baz-route 2m56s helloworld-zufardhiyaulhaq-com-corge-route 2m53s helloworld-zufardhiyaulhaq-com-foo-route 2m57s helloworld-zufardhiyaulhaq-com-garply-route 2m51s helloworld-zufardhiyaulhaq-com-grault-route 2m52s helloworld-zufardhiyaulhaq-com-quux-route 2m54s helloworld-zufardhiyaulhaq-com-qux-route 2m55s

kubectl get RateLimitService NAME AGE public-gateway-ratelimit-service 2m33s


3. Check EnvoyFilter

kubectl get envoyfilter NAME AGE helloworld-zufardhiyaulhaq-com-bar-route-1.8 3m7s helloworld-zufardhiyaulhaq-com-bar-route-1.9 3m7s helloworld-zufardhiyaulhaq-com-baz-route-1.8 3m7s helloworld-zufardhiyaulhaq-com-baz-route-1.9 3m6s helloworld-zufardhiyaulhaq-com-corge-route-1.8 3m8s helloworld-zufardhiyaulhaq-com-corge-route-1.9 3m4s helloworld-zufardhiyaulhaq-com-foo-route-1.8 3m8s helloworld-zufardhiyaulhaq-com-foo-route-1.9 3m7s helloworld-zufardhiyaulhaq-com-garply-route-1.8 3m10s helloworld-zufardhiyaulhaq-com-garply-route-1.9 3m8s helloworld-zufardhiyaulhaq-com-grault-route-1.8 3m10s helloworld-zufardhiyaulhaq-com-grault-route-1.9 3m7s helloworld-zufardhiyaulhaq-com-quux-route-1.8 3m9s helloworld-zufardhiyaulhaq-com-quux-route-1.9 3m5s helloworld-zufardhiyaulhaq-com-qux-route-1.8 3m11s helloworld-zufardhiyaulhaq-com-qux-route-1.9 3m6s

istio-public-gateway-1.8 3m11s istio-public-gateway-1.9 3m11s


4. Check Ratelimit

kubectl get service NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE public-gateway-ratelimit-service ClusterIP 10.32.214.174 8080/TCP,8081/TCP,6070/TCP 4m17s

kubectl get deployment NAME READY UP-TO-DATE AVAILABLE AGE public-gateway-ratelimit-service 2/2 2 2 4m53s

kubectl get configmap NAME DATA AGE public-gateway-ratelimit-service-config 1 5m14s public-gateway-ratelimit-service-config-env 4 5m14s

kubectl port-forward svc/public-gateway-ratelimit-service 6070:6070 curl http://127.0.0.1:6070/rlconfig

public-gateway.path.corge-route_corge-route: unit=HOUR requests_per_unit=120 public-gateway.path.quux-route_quux-route: unit=HOUR requests_per_unit=60 public-gateway.method.garply-route_garply-route: unit=HOUR requests_per_unit=120 public-gateway.method.path.bar-route_bar-route: unit=HOUR requests_per_unit=120 public-gateway.method.path.foo-route_foo-route: unit=HOUR requests_per_unit=60 public-gateway.method.machineid.qux-route_qux-route: unit=HOUR requests_per_unit=90 public-gateway.method.machineid.baz-route_baz-route: unit=HOUR requests_per_unit=90 public-gateway.method.grault-route_grault-route: unit=HOUR requests_per_unit=60



### Checklist:
<!--- Go over all the following points, and put an `x` in all the boxes that apply. -->
<!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! -->

- [x] My code follows the code style of this project.
- [x] My change requires a change to the documentation.
  - [x] I have updated the documentation accordingly.
- [ ] I have written new tests for my changes.
  - [ ] My changes successfully ran and pass tests locally.