kubernetesgoogle-cloud-platformgoogle-kubernetes-enginekubernetes-ingresskong-ingress

How to set requests per second limit on GKE and Kong Ingress?


I have a cluster on GKE and I want to set a limit for incoming requests, but I cannot find a way to do it using Kong Ingress Controller. I can't find any documentation or info about this specific topic.


Solution

  • Following the steps in this article, I achieved the desired results by adding the rate limit plugin in my kongo ingress. To do so, first, update / create your ingress definition and add the annotations defined below:

    apiVersion: extensions/v1beta1
    kind: Ingress
    metadata:
      name: func
      namespace: default
      annotations:
        kubernetes.io/ingress.class: kong   # <-- THIS
        plugins.konghq.com: http-ratelimit  # <-- THIS
    spec:
    ...
    

    After, to finally set the rate-limit, use this definition and apply it in your kubernetes cluster:

    apiVersion: configuration.konghq.com/v1
    kind: KongPlugin
    metadata:
      name: http-ratelimit
      namespace: default
    config:
      policy: local
      second: 1
    plugin: rate-limiting 
    

    This will create a restriction of 1 request per second in your ingress. If you want anything different, just change the config section with your own configuration. Check the plugin's documentation for all possible configurations.