[英]nginx-ingress config map snippets being ignored by the nginx.conf
I have a kubernetes cluster, where I have deployed an nginx ingress controller using thehelm nginx-ingress chart .我有一个 kubernetes 集群,在那里我使用helm nginx-ingress chart部署了一个 nginx 入口控制器。
I need to add some custom config to the nginx.conf file that is generated in the nginx-controller-pod, and I am seeing an issue where if I add a one line option such as proxy-buffer-size: "512k"
I can see this reflected in the nginx.conf file and everything works as expected.我需要向在 nginx-controller-pod 中生成的 nginx.conf 文件添加一些自定义配置,并且我看到一个问题,如果我添加一个单行选项,例如
proxy-buffer-size: "512k"
我可以看到这反映在 nginx.conf 文件中,一切都按预期工作。
However, if I attempt to add a snippet to accomplish the same thing:但是,如果我尝试添加一个片段来完成同样的事情:
location-snippet: |
proxy_buffer_size "512k";
It is as though this is ignored by the nginx.conf file and the proxy_buffer_size
setting remains at it's default value.这好像被 nginx.conf 文件忽略了,并且
proxy_buffer_size
设置保持它的默认值。
I need to be able to add http-snippet
, server-snippet
and location-snippet
overrides but whether I try to add them to the ConfigMap or as an annotation in the Ingress.yaml file they are always ignored.我需要能够添加
http-snippet
、 server-snippet
和location-snippet
覆盖,但是无论我尝试将它们添加到 ConfigMap 还是作为 Ingress.yaml 文件中的注释,它们总是被忽略。
My Ingress yaml file:我的入口 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
My nginx config map:我的 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;
}
If you'd like to modify your Kubernetes Ingress
the annotation options are these:如果您想修改 Kubernetes
Ingress
,注释选项如下:
nginx.ingress.kubernetes.io/configuration-snippet
for an nginx location block snippet nginx.ingress.kubernetes.io/configuration-snippet
用于 nginx 位置块片段nginx.ingress.kubernetes.io/server-snippet
for a snippet in the nginx config service block nginx.ingress.kubernetes.io/server-snippet
用于 nginx 配置服务块中的片段Looks like you are using nginx.org/location-snippets:
for that case.看起来您正在使用
nginx.org/location-snippets:
对于这种情况。
There's also a YAML invalid syntax on nginx config example and also you should use plurals as in server-snippets
according to this example .在 nginx 配置示例中还有一个 YAML 无效语法,根据这个示例,您也应该像在
server-snippets
一样使用复数。 There's a typo in the docs as of this writing.在撰写本文时, 文档中有一个错字。 Opened this ticket to follow up.
打开这张票跟进。
It should be something like this:它应该是这样的:
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;
}
instead of this:而不是这个:
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;
}
Notice the indentation of the last curly brace.注意最后一个花括号的缩进。
It turns out that my problem was due to the content of the snippet that I was applying.事实证明,我的问题是由于我正在应用的代码片段的内容。 Every time you run
kubectl apply -f myconfigmap.yaml
, a validation is run against the changes that you are trying to apply to the nginx.conf.每次运行
kubectl apply -f myconfigmap.yaml
,都会针对您尝试应用到 nginx.conf 的更改运行验证。 When this validation fails, it fails silently and there is nothing to alert you to this in the terminal.当此验证失败时,它会以静默方式失败,并且终端中没有任何提醒您这一点。
In fact, you still get the configmap/nginx-ingress-controller configured
message.实际上,您仍然会收到
configmap/nginx-ingress-controller configured
消息。
For example, when I add this to the config map, it updates the nginx.conf as expected:例如,当我将其添加到配置映射时,它会按预期更新 nginx.conf:
http-snippet: |
sendfile on;
However, when I add this, nothing changes:但是,当我添加它时,没有任何改变:
http-snippet: |
sendfile on;
tcp_nopush on;
The reason being that this has failed validation, but the only way to find that out is to look at the logs of the nginx ingress controller pod.原因是这没有通过验证,但找到它的唯一方法是查看 nginx 入口控制器 pod 的日志。 In this instance I see:
在这种情况下,我看到:
Error: exit status 1
2018/10/16 07:45:49 [emerg] 470#470: "tcp_nopush" directive is duplicate in
/tmp/nginx-cfg468835321:245
nginx: [emerg] "tcp_nopush" directive is duplicate in /tmp/nginx-cfg468835321:245
nginx: configuration file /tmp/nginx-cfg468835321 test failed
So I was duplicating a directive that already existed.所以我复制了一个已经存在的指令。
I spent a day untill got that for ingress-nginx (from Kubernetes) there are *-snippet
, but for nginx-ingress (from NGINX) that *-snippets
with s .我花了一天的时间,直到ingress-nginx (来自 Kubernetes)有
*-snippet
,但对于nginx-ingress (来自 NGINX), *-snippets
与s 。
Look here:看这里:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.