Home > OS >  Add Custom headers in Istio Virtual service
Add Custom headers in Istio Virtual service

Time:11-26

I am using Istio 1.10.0 with minikube. Kubernetes server version is 1.19.8.

How to add multiple headers in http request? Is it possible to place dynamic values like request.headers["Host"]?

X-Forwarded-Host $host;
X-Forwarded-Port 9090; X-Forwarded-Proto http;

Below sample is working fine for adding response header.

apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  annotations:
    helm.sh/hook: pre-install, pre-upgrade
  creationTimestamp: "2021-11-22T13:01:36Z"
  generation: 8
  name: direct-vs
  namespace: cvrm
  resourceVersion: "72069"
  selfLink: /apis/networking.istio.io/v1beta1/namespaces/cvrm/virtualservices/cvrm-direct-vs
  uid: d398a13e-fd81-4ada-8e36-617287cae1bc
spec:
  gateways:
  - gateway.istio-system.svc.cluster.local
  hosts:
  - '*'
  http:
  - match:
    - uri:
        prefix: /console
    route:
    - destination:
        host: console-bs.cvrm.svc.cluster.local
        port:
          number: 8087
      headers:
        response:
          add:
            Custom-Header: test

CodePudding user response:

You add headers to requests the same way you did with response.

...
headers:
  request:
    add:
      foo: bar
...

If you want to add multiple headers added you can try

...
headers:
  request:
    add:
      foo: foo
      bar: bar
...

It's not possible to add dynamic values in Istio manifests.

  • Related