Kubernetes ExternalName Service Add Headers

12/5/2018

TLDR: I'm running a kubernetes cluster using AKS. I have created an external name service to proxy to an external address. I would like to add a 'Host' header to the request. How should I go about doing this?

For more context I have an ingress controller that handles all incoming traffic. I want to route a subset of that traffic (based on route) to an external Azure Function. I have set up an ExternalName service with the hostname of my Azure Function and am routing the traffic to it. However, because of the way Microsoft handles routing to it's functions a 'Host' value with the correct FQDN is required in the header.

I don't want to make whoever sends the original request include this in the header so I'd like to add it on their behalf when traffic is proxy'd to the Azure Function.

Here is my service file:

kind: Service
apiVersion: v1
metadata:
  name: azure-function-proxy-service
  labels:
    app: proxy-service
spec:
  type: ExternalName
  externalName: azure-function.azurewebsites.net

And the relevant ingress rules code:

- host: hostto.proxy.net
http:
  paths:
  - path: /route/to/proxy
    backend:
      serviceName: azure-function-proxy-service
      servicePort: 80
-- Dillon Courts
kubernetes
kubernetes-ingress
kubernetes-service

2 Answers

12/6/2018

I think you can use the Canary feature in ingress-nginx. If you add the annotation nginx.ingress.kubernetes.io/canary: "true" you will be able to use following rules

  • nginx.ingress.kubernetes.io/canary-by-header: The header to use for notifying the Ingress to route the request to the service specified in the Canary Ingress. When the request header is set to always, it will be routed to the canary. When the header is set to never, it will never be routed to the canary. For any other value, the header will be ignored and the request compared against the other canary rules by precedence.

  • nginx.ingress.kubernetes.io/canary-by-cookie: The cookie to use for notifying the Ingress to route the request to the service specified in the Canary Ingress. When the cookie value is set to always, it will be routed to the canary. When the cookie is set to never, it will never be routed to the canary. For any other value, the cookie will be ingored and the request compared against the other canary rules by precedence.

  • nginx.ingress.kubernetes.io/canary-weight: The integer based (0 - 100) percent of random requests that should be routed to the service specified in the canary Ingress. A weight of 0 implies that no requests will be sent to the service in the Canary ingress by this canary rule. A weight of 100 means implies all requests will be sent to the alternative service specified in the Ingress.

You can also read this article canary deployment with ingress-nginx which explains how to use canary-weight and canary-by-header.

-- Crou
Source: StackOverflow

12/7/2018

I found that what I really wanted to do was modify the header of a request as it passes through my ingress controller. The best option I found to do that was the nginx.ingress.kubernetes.io/configuration-snippet but it did not give me the fine grained control I wanted.

Ultimately I had to stand up an additional nginx instance to proxy the requests so that I could have total control over the nginx config.

-- Dillon Courts
Source: StackOverflow