Kubernetes nginx入口控制器不转发带下划线的头

ctrmrzij  于 2023-05-06  发布在  Kubernetes
关注(0)|答案(4)|浏览(270)

我遇到了一个问题,我的kubernetes nginx ingress控制器NOT转发带有下划线的头部。
我使用以下条目创建了一个名为my-release-ingress-nginx-controller的configMap。

enable-underscores-in-headers: "true"

在此之后,我通过描述nginx入口控制器pod检查了nginx.conf文件,使用此命令kubectl exec -it my-release-ingress-nginx-controller-d7648bcc8-6lfxv cat nginx.conf。在那里我发现了这个underscores_in_headers on;。即使在此切换之后,nginx仍然不会转发带有下划线的头部。
配置Map:

apiVersion: v1
kind: ConfigMap
metadata:
  name: my-release-ingress-nginx-controller
  namespace: default
data:
  enable-underscores-in-headers: "true"
  ignore-invalid-headers: "false"

ConfigMap描述:

Name:         my-release-ingress-nginx-controller
Namespace:    default
Labels:       <none>
Annotations:  
Data
====
enable-underscores-in-headers:
----
true
ignore-invalid-headers:
----
false
Events:
  Type    Reason  Age   From                      Message
  ----    ------  ----  ----                      -------
  Normal  CREATE  27s   nginx-ingress-controller  ConfigMap default/my-release-ingress-nginx-controller

部署描述

Args:
  /nginx-ingress-controller
  --publish-service=default/my-release-ingress-nginx-controller
  --election-id=ingress-controller-leader
  --ingress-class=nginx
  --configmap=default/my-release-ingress-nginx-controller

入口描述:

Name:             ingress-resource-1
Namespace:        default
Address:          172.31.14.220
Default backend:  default-http-backend:80 (<error: endpoints "default-http-backend" not found>)
Rules:
  Host                                               Path  Backends
  ----                                               ----  --------
  api.dev.com  
                                                     /   faq-dev:10013 (172.17.0.3:10013)
Annotations:                                         kubernetes.io/ingress.class: nginx
                                                     nginx.ingress.kubernetes.io/rewrite-target: /
Events:
  Type    Reason  Age                     From                      Message
  ----    ------  ----                    ----                      -------
  Normal  UPDATE  3m10s (x2443 over 20h)  nginx-ingress-controller  Ingress default/ingress-resource-1
  Normal  UPDATE  2m10s (x2483 over 20h)  nginx-ingress-controller  Ingress default/ingress-resource-1

PS:我已经在AWS ec2服务器中使用minikube设置了一个单节点Kubernetes集群。此外,入口配置为部署而不是daemonset。配置的入口是来自此存储库的kubernetes入口-https://github.com/kubernetes/ingress-nginx

k2arahey

k2arahey1#

请试试这个

apiVersion: v1
kind: ConfigMap
data:
  enable-underscores-in-headers: "true"
  ignore-invalid-headers: "false"
metadata:
  name: nginx-configuration
  namespace: default

并将其包含在nginx-ingress-controller-deployment中

containers:
  - name: nginx-ingress-controller
    image: <YOUR NGINX INGRSS IMAGE_NAME>
    args:
      - /nginx-ingress-controller
      - --configmap=$(POD_NAMESPACE)/nginx-configuration
    env:
      - name: POD_NAME
        valueFrom:
          fieldRef:
            fieldPath: metadata.name
      - name: POD_NAMESPACE
        valueFrom:
          fieldRef:
            fieldPath: metadata.namespace
pbossiut

pbossiut2#

apiVersion: v1
kind: ConfigMap
data:
  enable-underscores-in-headers: "true"
metadata:
  name: nginx-configuration
  namespace: default

在标题中启用下划线
在将其添加到配置中之后,需要滚动重启以获取配置。

57hvy0tb

57hvy0tb3#

使用下面的menifest创建新的configmap &删除nginx控制器的pod,这基本上是使用新的configmap配置创建新的nginx控制器。

apiVersion: v1
data:
  enable-underscores-in-headers: "true"
  ignore-invalid-headers: "false"
kind: ConfigMap
metadata:
  name: my-release-ingress-nginx-controller
  namespace: default
klr1opcd

klr1opcd4#

如果有人使用ingress-nginx helm chart,解决方案是:https://github.com/kubernetes/ingress-nginx/blob/e09e40af1ad33cf748ee92502f61ec2b6f741b96/charts/ingress-nginx/templates/controller-configmap.yaml#L26
配置值:

values: |
    controller:
      config:
          enable-underscores-in-headers: "true"
          ignore-invalid-headers: "false"
          allow-snippet-annotations: "true"

相关问题