Kong ingress controller and path based routing


#1

I want to use the Ingress controller to register services in kong those services should be accessible through api.foo.bar/service/path.

I’ve created the service service.foo.bar in the ingress controller which I can access through the curl -vvvv https://api.foo.bar -H “Host: service.foo.bar” but I can’t find documentation on how I can pass the host header down to kong when accessing https://api.foo.bar/service


#2

@davideagle Please do not post in multiple threads.

I’ve replied to your post in another thread:


#3

How can I add regex in the path in the spec below? Thanks.

eg
spec:
rules:

  • http:
    paths:
    • path: /billing/{billingId}/details
      backend:
      serviceName: billing
      servicePort: 80

#4

@CuNguyen You can create an Ingress rule based on regex like you posted:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: my-regex
spec:
  rules:
  - http:
      paths:
      - path: "/billing/{billingId}/details"
        backend:
          serviceName: http-svc
          servicePort: 80

Are you facing any specific problem?


#5

@hbagdi Thanks to your promptly response. I did try that. But when I tried to access it thru KONG it returns

GET /billing/abc123/details
    {
        "message": "no route and no API found with those values"
    }

Then I replaced {billingId} as regex S+ for any non-whitespace characters (as in Kong doc).

  • With \S+, ingress returned invalid escapse character
  • With \S+, ingress returned invalid regex
  • With \\S+, ingress passed, but receive 404 when access kong, same as using {billingId}.

My ingress.ymal looks like below (a copy from your article.

My questions is how to include the {billingid} in the path that pass ingress and also accessible thru KONG?

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: app-name
  annotations:
    kubernetes.io/ingress.class: "kong"
spec:
  rules:
    - host:
      http:
        paths:
          - path: "/billing/\\S+/details"
            backend:
              serviceName: app-name
              servicePort: 443
          - path: "/checksense"
            backend:
              serviceName: app-name
              servicePort: 443

#6

It turns out that Ingress Spec supports the POSIX regular expression (as defined by IEEE Std 1003.1) and not PCRE, which is used by Kong.

This means that you can use only a subset of regular expressions that are valid POSIX regexes.

Since, it’s an ID that you are trying express, I imagine it would be possible for you to know which characters can be present in the ID?

The following Ingress is satisfied and works properly for me, and you can build up on top of it:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: my-regex
spec:
  rules:
  - http:
      paths:
      - path: "/billing/[a-z1-3]+/details"
        backend:
          serviceName: http-svc
          servicePort: 80

Please note that I put the above content into a YAML file on disk and then apply that, to get around escape issues with shells.

Hope this helps!