According to this article one need to set some nginx properties when running a .NET Core 2.x application using https and Azure AD Authentication behind Nginx in a Kubernetes cluster:
.Net Core behind NGINX returns 502 Bad Gateway after authentication by IdentityServer4
The answer outlines how to do this for a regular Nginx installation, but I would like to do this when installing Nginx in a Kubernetes cluster using Helm.
These are the Nginx properties one need to set:
nginx.conf:
http{
...
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
large_client_header_buffers 4 16k;
...
}
default.conf:
location /{
...
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
...
}
The command I use to install Nginx in the Kubernetes cluster is:
helm install stable/nginx-ingress --namespace kube-system
How does one set the above properties when installing Nginx using Helm in a Kubernetes cluster?
I found that the simplest solution is to use annotations on the Nginx ingress like this:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: test-ingress
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/proxy-buffer-size: "16k"
nginx.ingress.kubernetes.io/rewrite-target: /
...
It is possible to customize nginx configuration using ConfigMap.
This is an example
after adding the ConfigMap if nginx doesn't get updated, update your nginx chart using Helm:helm upgrade [RELEASE] [CHART]
heml upgrade my-release stable/nginx-ingress
if you don't know the [RELEASE] use following command:helm list
Fully agree with @Mozafar Gholami, you can change parameters using ConfigMap while deploying nginx or update your current configuration. To update parameters before installation suggest you next:
1.fetch chart to your local machine and unzip it:
helm fetch stable/nginx-ingress
tar -xzf nginx-ingress-1.1.4.tgz
example for you:
controller:
name: controller
image:
repository: quay.io/kubernetes-ingress-controller/nginx-ingress-controller
tag: "0.21.0"
pullPolicy: IfNotPresent
# www-data -> uid 33
runAsUser: 33
config:
proxy-buffer-size: "128k"
proxy-buffers: "4 256k"
3.check what will be added to new configmap
helm template . | less
4. install chart
helm install --name nginx-ingress --namespace kube-system ./nginx-ingress
Please keep in mind that:
Instead of ConfigMaps you can change parameters with Annotations.
Unfortunately NOT ALL parameters can be changed in nginx-ingress by above approach.
For more information reading the nginx-ingress customization page where you can find all values you are able to change. For example in your case I wasnt able to update proxy_busy_buffers_size
and large_client_header_buffers
parameters.
Hope this help you.