Configure Ingress controller to forward custom http headers

微笑、不失礼 提交于 2019-12-21 17:53:54

问题


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": [
        {}
      ]
    }
  }
}

回答1:


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";



回答2:


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



来源:https://stackoverflow.com/questions/54243311/configure-ingress-controller-to-forward-custom-http-headers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!