# How to use KongIngress to redirect to different backend path?

**URL:** <https://discuss.konghq.com/t/how-to-use-kongingress-to-redirect-to-different-backend-path/3848>\
**Category:** Questions\
**Tags:** kubernetes\
**Created:** [June 26, 2019, 6:43pm UTC](https://discuss.konghq.com/t/how-to-use-kongingress-to-redirect-to-different-backend-path/3848 "2019-06-26T18:43:17Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![fgsalomon](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/fgsalomon/32/2153_2.png) [@fgsalomon](https://discuss.konghq.com/u/fgsalomon)\
**Post date:** [June 26, 2019, 6:43pm UTC](https://discuss.konghq.com/t/how-to-use-kongingress-to-redirect-to-different-backend-path/3848/1 "2019-06-26T18:43:17Z")

</div>

Hi,

We have deployed services that expect to be called with /{service\_path} and we’d like to access some of them through ${PROXY\_IP}/something/{service\_path} instead of ${PROXY\_IP}/{service\_path}.

We are using for all our services:

```
apiVersion: configuration.konghq.com/v1
kind: KongIngress
metadata:
  name: kongingress-api
route:
  strip_path: false

```

I guess we have to create a new KongIngress that somehow uses proxy rules to change the path but I couldn’t find more documentation than [this](https://github.com/Kong/kubernetes-ingress-controller/blob/master/docs/custom-resources.md#kongingress) and I don’t know how to proceed.

How can we define a regex to remove “/something/” from the path?

Thank you.

---

<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:** [June 28, 2019, 5:03pm UTC](https://discuss.konghq.com/t/how-to-use-kongingress-to-redirect-to-different-backend-path/3848/2 "2019-06-28T17:03:28Z")

</div>

Please note that KongIngress is an extension to the Ingress resource.

You will need to set strip\_path to true and also set proxy.path property to ${service\_path}.

---

<div class="post-metadata">

**Author:** ![fgsalomon](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/fgsalomon/32/2153_2.png) [@fgsalomon](https://discuss.konghq.com/u/fgsalomon)\
**Post date:** [June 29, 2019, 10:23am UTC](https://discuss.konghq.com/t/how-to-use-kongingress-to-redirect-to-different-backend-path/3848/3 "2019-06-29T10:23:00Z")

</div>

Thank you for your fast reply Harry.

I tried that but it’s not working.

This is how I defined the KongIngress:

```
apiVersion: configuration.konghq.com/v1
kind: KongIngress
metadata:
  name: kongingress-api-staging
  namespace: staging
proxy:
  path: /myservice/
route:
  strip_path: true

```

This the Ingress for my service:

```
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: myservice-ingress
  namespace: staging
  annotations:
    kubernetes.io/ingress.class: "kong"
    configuration.konghq.com: kongingress-api-staging
 spec:
   rules:
   - http:
     paths:
       - path: /staging/myservice/
         backend:
           serviceName: myservice
           servicePort: rest

```

I expect this configuration to proxy calls to “/staging/myservice/” to myservice using as path “/myservice/” however it seems that the property proxy.path is not adding “/myservice/” to the stripped path. For example if I call “/staging/myservice/ui” in the service logs it shows:

```
2019-06-29 12:05:20.257 CEST 10.56.2.28 - - [29/Jun/2019:10:05:20 +0000] "GET /ui HTTP/1.1" 404 206 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/75.0.3770.90 Chrome/75.0.3770.90 Safari/537.36"

```

In addition, if this would work I’d like to make the kongingress-api-staging more generic to work with many services ("/staging/mysecondservice/", “/staging/mythirdservice/”, and so on )

I’m using kong-ingress-controller:0.4.0

---

<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:** [July 1, 2019, 4:31pm UTC](https://discuss.konghq.com/t/how-to-use-kongingress-to-redirect-to-different-backend-path/3848/4 "2019-07-01T16:31:58Z")

</div>

To configure any specific setting for a Kong service object, you will need to put the `configuration.konghq.com` annotation on the Kubernetes service resource (since a k8s service maps to a Kong service).

So, you need to add that annotation `myservice` service resource.

> [@fgsalomon](#):
>
> In addition, if this would work I’d like to make the kongingress-api-staging more generic to work with many services (“/staging/mysecondservice/”, “/staging/mythirdservice/”, and so on )

This should definitely be possible.

---

<div class="post-metadata">

**Author:** ![fgsalomon](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/fgsalomon/32/2153_2.png) [@fgsalomon](https://discuss.konghq.com/u/fgsalomon)\
**Post date:** [July 2, 2019, 9:01am UTC](https://discuss.konghq.com/t/how-to-use-kongingress-to-redirect-to-different-backend-path/3848/5 "2019-07-02T09:01:44Z")

</div>

Sorry, I forgot to add the Service definition on the previous post but I was already using the `configuration.konghq.com` annotation:

```
apiVersion: v1
kind: Service
metadata:
  name: myservice
  namespace: staging
  annotations:
     configuration.konghq.com: myservice
spec:
  ports:
  - name: rest
    port: 9097
    protocol: TCP
    targetPort: 4000
 type: ClusterIP

```

I can see in Konga how the proxy.path property is not being set even though is defined in the KongIngress resource (but the strip\_path property is working ok). If I change the path in the service details section in Konga the redirection works.

What am I doing wrong?

---

<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:** [July 2, 2019, 4:36pm UTC](https://discuss.konghq.com/t/how-to-use-kongingress-to-redirect-to-different-backend-path/3848/6 "2019-07-02T16:36:48Z")

</div>

Shouldn’t your annotation be `configuration.konghq.com: kongingress-api-staging` so that it is associated with the correct KongIngress resource?

---

<div class="post-metadata">

**Author:** ![fgsalomon](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/fgsalomon/32/2153_2.png) [@fgsalomon](https://discuss.konghq.com/u/fgsalomon)\
**Post date:** [July 2, 2019, 4:48pm UTC](https://discuss.konghq.com/t/how-to-use-kongingress-to-redirect-to-different-backend-path/3848/7 "2019-07-02T16:48:37Z")

</div>

I’m using that annotation on the Ingress resource. Isn’t that what I am supposed to do?

---

<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:** [July 2, 2019, 5:54pm UTC](https://discuss.konghq.com/t/how-to-use-kongingress-to-redirect-to-different-backend-path/3848/8 "2019-07-02T17:54:35Z")

</div>

Allow me to explain.  
When you use `configuration.konghq.com` annotation on Ingress resource, it overrides the properties of the routes corresponding to that particular ingress resource.

When you the same annotation on the service resource, it overrides the the properties of the service in Kong.

The value of the annotation should be the name of the KongIngress resource that you would like to reference.

In this case, you want to reference `kongingress-api-staging` KongIngress resource on the `myservice` resource so that the Kong service path property is overriden with `/myservice/`.

And that is why the annotation should be present on the Ingress as well as Service resource.

Hope that helps.

---

<div class="post-metadata">

**Author:** ![fgsalomon](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/fgsalomon/32/2153_2.png) [@fgsalomon](https://discuss.konghq.com/u/fgsalomon)\
**Post date:** [July 3, 2019, 8:38am UTC](https://discuss.konghq.com/t/how-to-use-kongingress-to-redirect-to-different-backend-path/3848/9 "2019-07-03T08:38:55Z")

</div>

I see. I’ve changed the annotation and now is working!  
Thank you very much Harry!

---

<div class="post-metadata">

**Author:** ![Joakim\_Waltersson](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/joakim_waltersson/32/1150_2.png) [@Joakim\_Waltersson](https://discuss.konghq.com/u/Joakim_Waltersson)\
**Post date:** [July 5, 2019, 3:22pm UTC](https://discuss.konghq.com/t/how-to-use-kongingress-to-redirect-to-different-backend-path/3848/10 "2019-07-05T15:22:08Z")

</div>

According to the documentation, ([here](https://github.com/Kong/kubernetes-ingress-controller/blob/master/docs/custom-resources.md#kongingress)), it is enough to use the same name for the Ingress and KongIngress resource. I have however observed the same as @fgsalomon where the strip\_path property is applied but not the path property until you add the annotation to the Service, so is the documentation wrong or am I missing something? (I’m rather new to Kubernetes and still haven’t fully grasped the Ingress concept I think).

---

<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:** [July 9, 2019, 1:05am UTC](https://discuss.konghq.com/t/how-to-use-kongingress-to-redirect-to-different-backend-path/3848/11 "2019-07-09T01:05:54Z")

</div>

> [@Joakim\_Waltersson](#):
>
> so is the documentation wrong or am I missing something?

The documentation is outdated and partially wrong.
