# Kong ingress controller and path based routing

**URL:** <https://discuss.konghq.com/t/kong-ingress-controller-and-path-based-routing/2956>\
**Category:** Questions\
**Tags:** kubernetes\
**Created:** [March 7, 2019, 3:18pm UTC](https://discuss.konghq.com/t/kong-ingress-controller-and-path-based-routing/2956 "2019-03-07T15:18:15Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![davideagle](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/davideagle/32/785_2.png) [@davideagle](https://discuss.konghq.com/u/davideagle)\
**Post date:** [March 7, 2019, 3:18pm UTC](https://discuss.konghq.com/t/kong-ingress-controller-and-path-based-routing/2956/1 "2019-03-07T15:18:15Z")

</div>

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](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](https://api.foo.bar/service)

---

<div class="post-metadata">

**Author:** ![hbagdi](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/hbagdi/32/562_2.png) [@hbagdi](https://discuss.konghq.com/u/hbagdi)\
**Post date:** [March 11, 2019, 3:59pm UTC](https://discuss.konghq.com/t/kong-ingress-controller-and-path-based-routing/2956/2 "2019-03-11T15:59:09Z")

</div>

@davideagle Please do not post in multiple threads.

I’ve replied to your post in another thread:

> [@Kong Ingress controller and path base routing?](https://discuss.konghq.com/t/kong-ingress-controller-and-path-base-routing/1944/6):
>
> Do you specifically need that host header? Creating the following ingress will actually configure Kong to route the requests to your upstream. It is currently not possible to alert the host header that Kong Ingress uses for upstream calls. apiVersion: extensions/v1beta1 kind: Ingress metadata: name: foo-bar spec: rules: - host: api.foo.bar http: paths: - path: /service backend: serviceName: service.foo.bar servicePort: 80

---

<div class="post-metadata">

**Author:** ![CuNguyen](https://avatars.discourse-cdn.com/v4/letter/c/43a26b/32.png) [@CuNguyen](https://discuss.konghq.com/u/CuNguyen)\
**Post date:** [March 21, 2019, 6:02am UTC](https://discuss.konghq.com/t/kong-ingress-controller-and-path-based-routing/2956/3 "2019-03-21T06:02:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![hbagdi](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/hbagdi/32/562_2.png) [@hbagdi](https://discuss.konghq.com/u/hbagdi)\
**Post date:** [March 21, 2019, 9:19pm UTC](https://discuss.konghq.com/t/kong-ingress-controller-and-path-based-routing/2956/4 "2019-03-21T21:19:07Z")

</div>

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

```auto
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?

---

<div class="post-metadata">

**Author:** ![CuNguyen](https://avatars.discourse-cdn.com/v4/letter/c/43a26b/32.png) [@CuNguyen](https://discuss.konghq.com/u/CuNguyen)\
**Post date:** [March 21, 2019, 10:35pm UTC](https://discuss.konghq.com/t/kong-ingress-controller-and-path-based-routing/2956/5 "2019-03-21T22:35:20Z")

</div>

@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](https://discuss.konghq.com/t/a-few-words-on-regex-uris-usage-and-common-pitfalls/506)).

- 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](https://konghq.com/blog/observability-kubernetes-kong/).

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
```

---

<div class="post-metadata">

**Author:** ![hbagdi](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/hbagdi/32/562_2.png) [@hbagdi](https://discuss.konghq.com/u/hbagdi)\
**Post date:** [March 22, 2019, 4:05pm UTC](https://discuss.konghq.com/t/kong-ingress-controller-and-path-based-routing/2956/6 "2019-03-22T16:05:16Z")

</div>

It turns out that [Ingress Spec](https://github.com/kubernetes/kubernetes/blob/7d75b73e1d72cef7a0f0e2804f8e0a582ccb6b61/staging/src/k8s.io/api/networking/v1beta1/types.go#L170-L178) 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:

```auto
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!

---

<div class="post-metadata">

**Author:** ![CuNguyen](https://avatars.discourse-cdn.com/v4/letter/c/43a26b/32.png) [@CuNguyen](https://discuss.konghq.com/u/CuNguyen)\
**Post date:** [March 25, 2019, 2:55am UTC](https://discuss.konghq.com/t/kong-ingress-controller-and-path-based-routing/2956/7 "2019-03-25T02:55:04Z")

</div>

Thanks!

I also got it worked last Friday with [a-zA-Z0-9]+  
The id, when fully implemented, would be an encrypted id that may contain any non-whitespace characters (that’s why I use \S+ :-)).

Very much appreciated your helps!
