Kubernetes NGINX Ingress changes HTTP request from a POST to a GET

5/16/2019

I'm using Kubernetes that is bundled with Docker-for-Mac. I'm trying to configure an Ingress that routes http requests starting with /v1/ to my backend service and /ui/ requests to my Angular app.

My issues seems to be that the HTTP method of the requests are changed by ingress (NGINX) from a POST to a GET.

I have tried various rewrite rules, but to no avail. I even switched from Docker-for-Mac to Minikube, but the result is the same.

If I use a simple ingress with no paths (just the default backend) then the service is getting the correct HTTP method. The ingress below works:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingress
spec:
  backend:
    serviceName: backend
    servicePort: 8080

But this ingress does not:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingress
  annotations:
    kubernetes.io/ingress.class: "nginx"

spec:
  rules:
  - http:
      paths:
      - path: /v1
        backend:
          serviceName: backend
          servicePort: 8080
      - path: /ui
        backend:
          serviceName: webui
          servicePort: 80

When I debug the "backend" service I see that the HTTP Request is a GET instead of a POST.

I read somewhere that NGINX rewrites issue a 308 (permanent) redirect and the HTTP method is changed from a GET to a POST, but if that is the case how can I configure my ingress to support different paths for different services that require POST calls?

-- Martin Steiner
kubernetes
nginx

1 Answer

5/20/2019

I found the solution to my problem. When I add host: to the configuration then the http method is not changed. Here is my current ingress yaml (the rewrite and regex are used to omit sending the /v1 as part of the backend URL)

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingress
  annotations:
    kubernetes.io/ingress.class: "nginx"
    nginx.ingress.kubernetes.io/rewrite-target: /$2
spec:
  rules:
  - host: localhost
    http:
      paths:
      - path: /v1(/|$)(.*)
        backend:
          serviceName: gateway
          servicePort: 8080
-- Martin Steiner
Source: StackOverflow