原因∶
nginx 对 header name 的字符做了限制,默认underscores_in_headers 为off,表示如果 header name 中包含下划线,则忽略掉,部署后就获取不到。
解决︰
1.在header里不要用“_"下划线,可以用驼峰命名或者其他的符号(如减号-)代替。nginx默认忽略掉下划线可能有些原因。
2.在nginx里的nginx.conf文件中配置 http 的部分添加: underscores_in_headers on;(默认值是off )
因为 K8S ingress 用了两层 nignx,所以需要处理2个地方
-
物理机上的 nginx , http 下加入 underscores_in_headers on;
-
在 ingress-nginx 的 ConfiMap 添加 enable-underscores-in-headers: "true"
cd /data/yaml/ingress-nginx
cp deploy.yaml deploy.yaml.20210617
vi deploy.yaml
# 找到下下面
# Source: ingress-nginx/templates/controller-configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
labels:
helm.sh/chart: ingress-nginx-3.30.0
app.kubernetes.io/name: ingress-nginx
app.kubernetes.io/instance: ingress-nginx
app.kubernetes.io/version: 0.46.0
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/component: controller
name: ingress-nginx-controller
namespace: ingress-nginx
data:
# 添加下面这行
enable-underscores-in-headers: "true"
# 重新加载
kubectl apply -f deploy.yaml