Helm [stable/nginx-ingress] Getting issue while passing headers

10/15/2019

Version of Helm and Kubernetes: Client: &version.Version{SemVer:"v2.14.1" and 1.13.7-gke.24

Which chart: stable/nginx-ingress [v0.24.1]

What happened: Trying to override headers using--set-string but it does not work as expected. It always gives issues with the parsing

/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|...

What you expected to happen: I want to override the header which the there by default in values.yam with custom headers

How to reproduce it (as minimally and precisely as possible): I have provided the comment to reproduce, 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"}' .

I tried to run in debug mode (--dry-run --debug), It shows me configmap like below,

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

It seems like its adding intent 4 instead of intent 2. Below warning also i'm getting, 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]

Kindly help me to pass the headers in the right way.

-- Dinesh SC
kubernetes
kubernetes-helm
nginx-ingress

1 Answer

10/30/2019

Note: controller.headers is deprecated, make sure to use the controller.proxySetHeaders instead.


Helm --set has some limitations.

Your best option is to avoid using the --set, and use the --values instead.

You can declare all your custom values in a file like this:

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

Then use it on install:

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

If you want to use --set anyway, you should use this notation:

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" 
-- Eduardo Baitello
Source: StackOverflow