Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Kubernetes] Allow to set custom headers on specific paths in ingress #4228

Open
osamamaruf opened this issue Nov 26, 2018 · 5 comments
Open
Labels
area/provider/k8s/ingress contributor/wanted Participation from an external contributor is highly requested kind/enhancement a new or improved feature. priority/P3 maybe

Comments

@osamamaruf
Copy link

Do you want to request a feature or report a bug?

Feature

What did you expect to see?

ATM annotations cannot be applied on specific paths like e.g. ingress.kubernetes.io/custom-response-headers . For example take the case of applying cache-control headers on static resources like .js, .png files.
We can

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: application-ingress
  namespace: abc
  annotations:
    kubernetes.io/ingress.class: 'traefik'    
	ingress.kubernetes.io/custom-response-headers: Cache-Control: private || Cache-Control: max-age=31536000
spec:
  rules:
  - host: 
    http:
      paths:
      - path: /abc1
        backend:
          serviceName: sabc1
          servicePort: 443
      - path: /abc2
        backend:
          serviceName: sabc2
          servicePort: 443

However the headers will be applied to all the paths. If possible we can apply a regex before specifying the each header to indicate on what files the header should be applied. If no regex is defined then it should apply on all something like this

  annotations:
    kubernetes.io/ingress.class: 'traefik'    
	ingress.kubernetes.io/custom-response-headers: (.js|.png)$ Cache-Control: private || (.js|.png)$ Cache-Control: max-age=31536000

would be good.

Further it would be great if this can be applied to specific path e.g.

- path: /abc1
        annotations:
          ingress.kubernetes.io/custom-response-headers: annotation for specific path
        backend:
          serviceName: sabc1
          servicePort: 443

@osamamaruf osamamaruf changed the title [Kuberbetes] Allow to set custom headers on specific paths in ingress [Kubernetes] Allow to set custom headers on specific paths in ingress Nov 26, 2018
@izern

This comment has been minimized.

@codeman9
Copy link

codeman9 commented Feb 8, 2019

I would also like a feature like this, but so that I can support custom request headers while doing service-weights. If the ingress.kubernetes.io/custom-[response,request]-headers was of type map[string]map[string]string, then traefik could support something like:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: application-ingress
  namespace: abc
  annotations:
    kubernetes.io/ingress.class: 'traefik'
    ingress.kubernetes.io/custom-response-headers: |
        sabc1: X-Custom-Response-Header:sabc1
        sabc2: X-Custom-Response-Header:sabc2
    ingress.kubernetes.io/custom-request-headers: |
        sabc1: X-Custom-Host-Header:sabc1.namespace1.svc.cluster.local
        sabc2: X-Custom-Host-Header:sabc2.namespace2.svc.cluster.local
    traefik.ingress.kubernetes.io/service-weights |
        sabc1: 25%
        sabc2: 75%
spec:
  rules:
  - host: mydomain.com
    http:
      paths:
      - path: /abc1
        backend:
          serviceName: sabc1
          servicePort: 443
      - path: /abc1
        backend:
          serviceName: sabc2
          servicePort: 443

because the ingress object can define multiple services in one, it seems to make sense that different headers could be provided to/from each service differently. The key for me is to be able to specify a different custom host header per service so that the next downstream proxy can route accordingly.

@earonesty
Copy link

Can't you just have multiple ingress definitions?

@mastoj
Copy link

mastoj commented Jan 21, 2021

I saw somewhere that nginx supports some kind of templating, so you could write something like:

"ingress.kubernetes.io/custom-request-headers": "l5d-dst-override:$service_name.$namespace.svc.cluster.local:8080"

Not exactly that, but similar. Is that also possible for traefik? If it isn't I need to create multiple ingress definitions.

@prajithp13
Copy link

Any work around for this?

@nmengin nmengin added the contributor/wanted Participation from an external contributor is highly requested label Jul 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/provider/k8s/ingress contributor/wanted Participation from an external contributor is highly requested kind/enhancement a new or improved feature. priority/P3 maybe
Projects
None yet
Development

No branches or pull requests

8 participants