Configure Ingress controller to forward custom http headers

1/17/2019

We are setting up an AKS cluster on Azure, following this guide

We are running 5 .Net Core API's behind an ingress controller, everything works fine, requests are being routed nicely. However, in our SPA Frontend, we are sending a custom http header to our API's, this header never seems to make it to the API's, when we inspect the logging in AKS we see the desired http header is empty. In development, everything works fine, we also see the http header is filled in our test environment in AKS, so i'm guessing ingress is blocking these custom headers.

Is there any configuration required to make ingress pass through custom http headers?

EDIT:

{
  "kind": "Ingress",
  "apiVersion": "extensions/v1beta1",
  "metadata": {
    "name": "myappp-ingress",
    "namespace": "myapp",
    "selfLink": "/apis/extensions/v1beta1/namespaces/myapp/ingresses/myapp-ingress",
    "uid": "...",
    "resourceVersion": "6395683",
    "generation": 4,
    "creationTimestamp": "2018-11-23T13:07:47Z",
    "annotations": {
      "kubernetes.io/ingress.class": "nginx",
      "nginx.ingress.kubernetes.io/allow-headers": "My_Custom_Header", //this doesn't work
      "nginx.ingress.kubernetes.io/proxy-body-size": "8m",
      "nginx.ingress.kubernetes.io/rewrite-target": "/"
    }
  },
  "spec": {
    "tls": [
      {
        "hosts": [
          "myapp.com"
        ],
        "secretName": "..."
      }
    ],
    "rules": [
      {
        "host": "myapp.com",
        "http": {
          "paths": [
            {
              "path": "/api/tenantconfig",
              "backend": {
                "serviceName": "tenantconfig-api",
                "servicePort": 80
              }
            },
            {
              "path": "/api/identity",
              "backend": {
                "serviceName": "identity-api",
                "servicePort": 80
              }
            },
            {
              "path": "/api/media",
              "backend": {
                "serviceName": "media-api",
                "servicePort": 80
              }
            },
            {
              "path": "/api/myapp",
              "backend": {
                "serviceName": "myapp-api",
                "servicePort": 80
              }
            },
            {
              "path": "/app",
              "backend": {
                "serviceName": "client",
                "servicePort": 80
              }
            }
          ]
        }
      }
    ]
  },
  "status": {
    "loadBalancer": {
      "ingress": [
        {}
      ]
    }
  }
}
-- Arne Deruwe
.net-core
azure
azure-aks
kubernetes
nginx-ingress

2 Answers

1/17/2019

If I want my ingress controller pass a custom header to my backend service, I can use this annotation in my ingress rule

nginx.ingress.kubernetes.io/configuration-snippet: |
  more_set_headers "Request-Id: $req_id";
-- c4f4t0r
Source: StackOverflow

1/22/2019

I ended up using the following configuration snippet:

nginx.ingress.kubernetes.io/configuration-snippet: |
  proxy_set_header My-Custom-Header $http_my_custom_header;

nginx makes all custom http headers available as embedded variable via the $http_ prefix, see this

-- Arne Deruwe
Source: StackOverflow