Helm [stable / nginx-ingress]传递标头时出现问题

时间:2019-10-15 08:57:40

标签: kubernetes kubernetes-helm nginx-ingress

Helm和Kubernetes的版本:客户端:&version.Version {SemVer:“ v2.14.1”和1.13.7-gke.24

哪个图表:稳定/ nginx入口[v0.24.1]

发生了什么:尝试使用--set-string覆盖标头,但无法按预期工作。它总是给解析带来问题

/usr/sbin/helm install --name cx-nginx-1 --set controller.name=cx-nginx-1 --set controller.kind=Deployment --set controller.service.loadBalancerIP= --set controller.metrics.enabled=true --set-string 'controller.headers={"X-Different-Name":"true","X-Request-Start":"test-header","X-Using-Nginx-Controller":"true"}' . Error: release cx-nginx-1 failed: ConfigMap in version "v1" cannot be handled as a ConfigMap: v1.ConfigMap.Data: ReadMapCB: expect { or n, but found [, error found in #10 byte of ...|","data":["\"X-Diffe|..., bigger context ...|{"apiVersion":"v1","data":["\"X-Different-Name\":\"true\"","\"X-Request-Start|...

您希望发生的事情:我想使用自定义标头覆盖默认情况下values.yam中的标头

如何再现(尽可能最小且精确): 我提供了评论以重制, helm install --name cx-nginx-1 --set controller.name=cx-nginx-1 --set controller.kind=Deployment --set controller.service.loadBalancerIP= --set controller.metrics.enabled=true --set-string 'controller.headers={"X-Different-Name":"true","X-Request-Start":"test-header","X-Using-Nginx-Controller":"true"}' .

我试图以调试模式(--dry-run --debug)运行,它向我显示如下的configmap,

apiVersion: v1
kind: ConfigMap
metadata:
  labels:
    app: nginx-ingress
    chart: nginx-ingress-1
    component: "cx-nginx-1"
    heritage: Tiller
    release: foiled-coral
  name: foiled-coral-nginx-ingress-custom-headers
  namespace: cx-ingress
data:
  - X-Different-Name:true
  - X-Request-Start:test-header
  - X-Using-Nginx-Controller:true

似乎它添加了意图4而不是意图2。在警告之下,我也得到了, Warning: Merging destination map for chart 'nginx-ingress'. Cannot overwrite table item 'headers', with non table value: map[X-Different-Name:true X-Request-Start:test-header X-Using-Nginx-Controller:true]

请帮助我以正确的方式传递标题。

1 个答案:

答案 0 :(得分:0)

注意:不建议使用controller.headers,请确保使用controller.proxySetHeaders


头盔--set有一些limitations

您最好的选择是避免使用--set,而改用--values

您可以在这样的文件中声明所有自定义值:

# values.yaml
controller:
  name: "cx-nginx-1"
  kind: "Deployment"
  service:
    loadBalancerIP: ""
  metrics:
    enable: true
  proxySetHeaders:
    X-Different-Name: "true"
    X-Request-Start: "true"
    X-Using-Nginx-Controller: "true"

然后在安装时使用它:

helm install --name cx-nginx-1 stable/nginx-ingress \
--values=values.yaml

如果您仍然想使用--set,则应使用以下表示法:

helm install --name cx-nginx-1 stable/nginx-ingress \
--set controller.name=cx-nginx-1 \
--set controller.kind=Deployment \
--set controller.service.loadBalancerIP= \
--set controller.metrics.enabled=true \
--set-string controller.proxySetHeaders.X-Different-Name="true" \
--set-string controller.proxySetHeaders.X-Request-Start="true" \
--set-string controller.proxySetHeaders.X-Using-Nginx-Controller="true"