1、首先添加一个configmap叫nginx-config
apiVersion: v1
data:
client-header-buffer-size: 32k
client-max-body-size: 5m
gzip-level: "7"
large-client-header-buffers: 4 32k
proxy-connect-timeout: 11s
proxy-read-timeout: 12s
use-geoip2: "true"
use-gzip: "true"
kind: ConfigMap
2、配置ingress-nginx-controller的deployment添加arg,指定configmap=kube-system/nginx-config
...
spec:
containers:
- args:
- /nginx-ingress-controller
- --default-backend-service=kube-system/nginx-ingress-default-backend
- --election-id=ingress-controller-leader
- --ingress-class=nginx
- --tcp-services-configmap=kube-system/tcp-services
- --configmap=kube-system/nginx-config
- --default-ssl-certificate=$(POD_NAMESPACE)/ssl-wehgc-com
...
3、登陆ingress-nginx的pod,查看是否生效
[root@k8s_client ~]# kubectl -n kube-system exec -it nginx-ingress-controller-58f7fcbc76-9n6z2 bash
www-data@nginx-ingress-controller-58f7fcbc76-9n6z2:/etc/nginx$ grep large_client_header_buffers nginx.conf
large_client_header_buffers 4 32k;
PS:注意 要用client-header-buffer-size而不是 client_header_buffer_size,要不然不会生效,因为配置普通nginx的时候是用client_header_buffer_size,而在K8s的configmap的时候要用client-header-buffer-size,但是登陆pod查看的时候仍然是以client_header_buffer_size显示。
来源:oschina
链接:https://my.oschina.net/u/4398470/blog/4927038