Kubernetes: Preserving HTTP method with NGINX Ingress simple fanout

3/23/2021

When we use a "simple fanout" Ingress pattern, as described here: https://v1-18.docs.kubernetes.io/docs/concepts/services-networking/ingress/#simple-fanout (we're using v1.18), the Ingress performs a simple redirect, sending 302 - Found

This causes the HTTP method to change to GET.

I'm trying to get the Ingress to give either a 307 or a 308 response instead.

I've tried using NGINX/k8s annotations, and I've tried applying the sort of approach here: https://stackoverflow.com/questions/56177198/kubernetes-nginx-ingress-changes-http-request-from-a-post-to-a-get but this doesn't work

We have 2 applications mapped to the same server using different ports behind the scenes.

Strangely enough, the POST is preserved fine with curl

-- pc3356
kubernetes
nginx

1 Answer

3/24/2021

In the end it's not really anything to do with K8S or NGINX:

The endpoint I wanted to use was mapped to "/" in the context (i.e. /blah/)

Since it's an API, it would be unusual to have something with a trailing slash, so I was referring to it by /blah, which the underlying application server rewrote to /blah/ with a 302.

Fixed it by using /v1 as the context (and ingress path), so I can have /v1/blah and it won't rewrite/redirect.

-- pc3356
Source: StackOverflow