配置 Ingress 控制器以转发自定义 http 标头

Arn*_*uwe 5 azure kubernetes .net-core azure-aks nginx-ingress

我们正在按照本指南在 Azure 上设置 AKS 集群

我们在入口控制器后面运行 5 个 .Net Core API,一切正常,请求路由很好。但是,在我们的 SPA 前端,我们正在向 API 发送自定义 http 标头,此标头似乎从未发送到 API,当我们检查 AKS 中的日志记录时,我们看到所需的 http 标头为空。在开发中,一切正常,我们还看到在 AKS 的测试环境中填充了 http 标头,因此我猜测 ingress 正在阻止这些自定义标头。

是否需要任何配置才能使入口通过自定义 http 标头?

编辑:

{
  "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": [
        {}
      ]
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

Arn*_*uwe 8

我最终使用了以下配置片段:

nginx.ingress.kubernetes.io/configuration-snippet: |
  proxy_set_header My-Custom-Header $http_my_custom_header;
Run Code Online (Sandbox Code Playgroud)

nginx 通过$http_前缀使所有自定义 http 标头可用作嵌入变量,请参阅此


归档时间:

查看次数:

8082 次

最近记录:

5 年,5 月 前