How can I apply a plugin on a specific route

Hello, I am currentyl moving to kong-ingress to manage my APIs and I am trying ta apply plugin on route and not directly on service. For exemple I have an backend API that need to allow cache only on some specific route, but the way I deploy plugin in kong do not allow me to specify route restriction.

for example, to put cache on some service i apply :

apiVersion: configuration.konghq.com/v1
kind: KongPlugin
plugin: proxy-cache
metadata:
  name: cache-api
config:
  strategy: memory
  cache_ttl: 60

and then I add {“metadata”:{“annotations”:{“plugins.konghq.com”:
“cache-validation-api\n”}}}’ to the service.

How can I apply plugin on route and not on the entire service ?

thanks

If you make 2 ingress, you can apply kong plugin only 1 route path

service : aaa
/bbb : not apply plugin
/ccc : apply plugin

[ Example ]
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
kubernetes.io/ingress.class: kong
spec:
rules:

  • http:
    paths:
    • backend:
      serviceName: aaa
      servicePort: 8080
      path: /bbb

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
kubernetes.io/ingress.class: kong
plugins.konghq.com: cache-api # apply plugin
spec:
rules:

  • http:
    paths:
    • backend:
      serviceName: aaa
      servicePort: 8080
      path: /ccc

Thanks for you answer !

I am okay with your solution it work indeed. However with such a solution I will tend to create one ingress for each route of my service isn’t it ? If I want to precisely manage my Cache time i could have situation where each of this time is different. I use to see the ingress ressource as something upper the services to manage the traffic toward them.

Is there any other way ?

I thought to use different service for the specific route that way I only apply the plugin to this service. But with that I am creating a lot of service for the same API.

What I am looking for (if it exist) is a way to specify in the plugin yaml (or during the creation of the plugin) the route that this plugin will target.

You can create two Ingress resources:

  • One contains all the rules or paths which shouldn’t be cached
  • And the other includes all of the routes that should be cached, apply the plugin annotation to this one.

And that’s it.
If you want to add new routes or paths, simply update the Ingress rule and you are good to go.

Thanks for your answers, I will handle my plugin deployment that way !