Hello,
First of all, thanks for your wonderful job.
Using NginX Controller in production without any issue on my side.
Would it be possible in the future to configure custom headers to be sent to the upstream via corresponding annotations on the ingress ?
It is currently possible using a ConfigMap however globally.
https://github.com/kubernetes/ingress/tree/master/examples/customization/custom-headers/nginx
Many thanks,
@aledbf while I would like to see a more specific solution where you could directly add custom headers as an annotation to a specific Ingress. This use case can already be realised with existing functionality, using configuration snippets, right?
I use something like:
kind: Ingress
metadata:
name: httpheaders-with-custom-headers
annotations:
kubernetes.io/ingress.class: "nginx"
ingress.kubernetes.io/configuration-snippet: |
more_set_headers "Hello: World";
...
@arjanschaaf - the example you gave isn't working for me - but I can use proxy_set_header - I'm wondering if the more module is not included with in my ingress controller containers?
@jemc my example is based on this part of the official documentation: https://github.com/kubernetes/ingress/tree/master/examples/customization/configuration-snippets/nginx and works in my setup.
Which Docker image are you using to launch your Ingress Controller container?
@arjanschaaf - I wasn't the one who set them up, but using kubectl describe, is looks like the image we're running is: gcr.io/google_containers/nginx-ingress-controller:0.9.0-beta.11
@jemc I think I see where the misunderstanding between us is coming from. The point of my original response was not so much about the usage of more_set_headers but about the usage of a configuration-snippet to inject custom behaviour instead of baking that into a new annotation. proxy_set_header is to be used if one wants to pass a header to the upstream server. more_set_headers can be used if one want to sent a response header back to the client.
Closing. You can use the annotation mentioned by @arjanschaaf
https://github.com/kubernetes/ingress/blob/master/controllers/nginx/configuration.md#configuration-snippet or use http-snippet, server-snippet or location-snippet in the configuration configmap to inject custom configuration
Hello, sorry if not the best place to ask such; but trying to better understand how server-snippets work (tried on SO, no luck :/)
I tried to do the following :
ingress.kubernetes.io/server-snippets: |
location ~* \.(?:ico|css|js|gif|jpe?g|png)$ {
expires 30d;
add_header Pragma public;
add_header Cache-Control "public";
}
But not seeing any results in the generated nginx.conf file in the pod. Is this normal ? Should such location implementation be done another way ? The more_set_headers do appear when set as shown here. Am using nginx beta17
Thx if any help
Doesn't work for me either. I think the documentation is out of date. I'm using this exact code, but no results. Also the ingress controller logs don't show any errors when updating the ingress.
Actually, the annotation itself may be incorrect. Check this answer on SO: https://stackoverflow.com/a/52783328/10781019
It uses this one instead: nginx.ingress.kubernetes.io/configuration-snippet
If anyone stumbles upon this, there is an update to the snippet annotation as follows:
kind: Ingress
metadata:
name: httpheaders-with-custom-headers
annotations:
kubernetes.io/ingress.class: "nginx"
nginx.ingress.kubernetes.io/configuration-snippet: |
more_set_headers "Hello: World";
...
Note the nginx.ingress.kubernetes.io/configuration-snippet
Hi :)
I'm using Rancher on top of Kubernetes, and I'm trying to pass the country code header to my workloads. I have enabled use-geoip2 inside ConfigMap, added licence key as an argument, but still can't get header value inside the container, do you maybe know what I'm missing here?
Kind regards!
@marcoroganovic please open a new issue describing what are you doing (please use the template issue)
@aledbf Thanks for your reply.
I've decided to ask on Slack after I read the guidelines for questions.
Most helpful comment
If anyone stumbles upon this, there is an update to the snippet annotation as follows:
Note the nginx.ingress.kubernetes.io/configuration-snippet