Setting up an ingress based on methods and incoming URI

Hello,

I am a bit confused on how to go about this specific task: create an ingress rule that routes requests coming from a URI containing “/abc/def” to “http/get” if the method of the request is GET or “http/post” if the method is POST.

I have been reading about KongIngress in the forum and it looks like this should be part of the solution, but I can’t find information on how to do a selection on methods or the incoming URI.

Any pointers, please?

You should be able to set request method using KongIngress CRD.

Check this doc.

route:
  methods:
  - POST
  - GET

Thank you @fomm ,

With the documentation, I have managed to get the GET part working:

I create an ingress and a KongIngress, I give them the same name to allow the routing on methods and then I patch the application service for the proxy part.

  ---
apiVersion: configuration.konghq.com/v1
kind: KongIngress
metadata:
  name: demo-ingress-ki
proxy:
  path: "/get-route"
route:
  methods:
  - GET
  strip_path: true

---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: demo-ingress-ki
  annotations:
    kubernetes.io/ingress.class: "kong"
    configuration.konghq.com: demo-service-ki
spec:
  rules:
  - http:
      paths:
      - path: "/cgi-bin/incoming"
        backend:
          serviceName: demo-service
          servicePort: 80

kubectl patch service demo-service -p ‘{“metadata”:{“annotations”:{“konghq.com/override":"demo-ingress-ki”}}}’

At this point, I don’t know how to also allow the POST to go to a “/post-route” rather than a “/get-route”.

Would you be able to provide some advice?

I think I worked this out, I am not sure this is the best approach, it looks pretty clunky. I have done the following:

Create 2 services, one named demo-service-get and one demo-service-post (everything else is the same). Add an annotation to each like this, the annotation will refer to two KongIngress (demo-ingress-ki-get and demo-ingress-ki-post)

kind: Service
metadata: 
  name: demo-service-get
  annotations:
    konghq.com/override: demo-ingress-ki-get
spec: 
  type: ClusterIP
[...whatever else...]

---
kind: Service
metadata: 
  name: demo-service-post
  annotations:
    konghq.com/override: demo-ingress-ki-post
spec: 
  type: ClusterIP
[...whatever elese...]

Create 2 KongIngress

  ---
apiVersion: configuration.konghq.com/v1
kind: KongIngress
metadata:
  name: demo-ingress-ki-get
proxy:
  path: "/get-route"
route:
  methods:
  - GET
  strip_path: true
  ---
apiVersion: configuration.konghq.com/v1
kind: KongIngress
metadata:
  name: demo-ingress-ki-post
proxy:
  path: "/get-route"
route:
  methods:
  - POST
  strip_path: true

Create two ingress, note that they will point to a different service and KongIngress. Note the konghq.com/override replacing the annotation of the first iteration.

---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: demo-ingress-ki-get
  annotations:
    kubernetes.io/ingress.class: "kong"
    konghq.com/override: demo-service-ki-get
spec:
  rules:
  - http:
      paths:
      - path: "/cgi-bin/incoming"
        backend:
          serviceName: demo-service-get
          servicePort: 80
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: demo-ingress-ki-post
  annotations:
    kubernetes.io/ingress.class: "kong"
   konghq.com/override: demo-service-ki-post
spec:
  rules:
  - http:
      paths:
      - path: "/cgi-bin/incoming"
        backend:
          serviceName: demo-service-post
          servicePort: 80

Any variation of this does not work and either the proxy or the route is not satisfied.


© 2019 Kong Inc.    Terms  •  Privacy  •  FAQ