我有一个kubernetes集群,我使用helm nginx-ingress chart部署了一个Nginx入口控制器.
我需要在Nginx-controller-pod中生成的Nginx.conf文件中添加一些自定义配置,我看到一个问题,如果我添加一行选项,如proxy-buffer-size:“512k”I可以看到这反映在Nginx.conf文件中,一切都按预期工作.
location-snippet: |
proxy_buffer_size "512k";
就好像Nginx.conf文件忽略了它,proxy_buffer_size设置保持默认值.
我需要能够添加http-snippet,server-snippet和location-snippet覆盖,但是我是否尝试将它们添加到ConfigMap或作为Ingress.yaml文件中的注释,它们总是被忽略.
我的Ingress yaml文件:
apiVersion: extensions/v1beta1
kind: Ingress
Metadata:
name: my-ingress
annotations:
kubernetes.io/ingress.class: Nginx
ingress.kubernetes.io/ssl-redirect: "true"
ingress.kubernetes.io/secure-backends: "true"
ingress.kubernetes.io/force-ssl-redirect: "true"
ingress.kubernetes.io/location-snippet: |
proxy_buffer_size 512k; --This does not update the Nginx.conf
spec:
tls:
- hosts:
- my.app.co.uk
secretName: tls-secret
rules:
- host: my.app.co.uk
http:
paths:
- path: /
backend:
serviceName: myappweb-service
servicePort: 80
我的Nginx配置图:
apiVersion: v1
kind: ConfigMap
Metadata:
labels:
app: nginx-ingress
chart: nginx-ingress-0.28.3
component: controller
heritage: Tiller
release: nginx-ingress
name: nginx-ingress-controller
namespace: default
data:
proxy-buffer-size: "512k" -- this works and updates the Nginx.conf
location-snippet: |
proxy_buffers 4 512k; -- this does not update the Nginx.conf
server-snippet: | -- this does not update the Nginx.conf
location /messagehub {
proxy_set_header Upgrade $http_upgrade;
proxy_http_version 1.1;
proxy_set_header X-Forwarded-Host $http_host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_set_header Connection "upgrade";
proxy_cache_bypass $http_upgrade;
}
如果您想修改Kubernetes Ingress,注释选项如下:
> Nginx.ingress.kubernetes.io/configuration-snippet用于Nginx位置块代码段
> Nginx.ingress.kubernetes.io/server-snippet,用于Nginx配置服务块中的代码段
看起来你正在使用Nginx.org/location-snippets:对于那种情况.
在Nginx配置示例中还有一个YAML无效语法,并且您应该根据此example在服务器片段中使用复数.在撰写本文时,docs中存在拼写错误.开放this ticket跟进.
它应该是这样的:
server-snippets: |
location /messagehub {
proxy_set_header Upgrade $http_upgrade;
proxy_http_version 1.1;
proxy_set_header X-Forwarded-Host $http_host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_set_header Connection "upgrade";
proxy_cache_bypass $http_upgrade;
}
而不是这个:
server-snippet: |
location /messagehub {
proxy_set_header Upgrade $http_upgrade;
proxy_http_version 1.1;
proxy_set_header X-Forwarded-Host $http_host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_set_header Connection "upgrade";
proxy_cache_bypass $http_upgrade;
}
注意最后一个花括号的缩进.