我已经使用 helm chart 在K8 cluster
上安装了ngnix
入口控制器。
helm install --name nginx-ingress stable/nginx-ingress --namespace kube-system
我想在入口控制器的ngnix.conf
文件中更新以下值ngnix
:
1. proxy-connect-timeout
2. proxy-read-timeout
3. location
{
add_header "Cache-Control" "max-age=0, no-cache, no-store, must-revalidate";
add_header "Pragma" "no-cache";
add_header "Expires" "-1";
}
我在下面使用了ingress.yaml:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: test-iningress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
nginx.ingress.kubernetes.io/proxy-connect-timeout: "300s"
nginx.ingress.kubernetes.io/proxy-read-timeout: "300s"
nginx.ingress.kubernetes.io/client-max-body-size: "0"
nginx.ingress.kubernetes.io/server-snippet: |
location / {
add_header "Cache-Control" "max-age=0, no-cache, no-store, must-revalidate";
add_header "Pragma" "no-cache";
add_header "Expires" "-1";
}
spec:
rules:
- host: {{ .Values.ingress.hosts }}
http:
paths:
- path: /ui
backend:
serviceName: sift-ui-service
servicePort: {{ .Values.service.sift_ui.port }}
然后当我使用 ngnix.conf检查 ngnix.conf 时
kubectl exec -it nginx-ingress-controller-b4477bdf7-gwt8v -n kube-system -- cat /etc/nginx/nginx.conf
proxy-connect-timeout
和proxy-read-timeout
不会更新。 它显示默认值,并且也不会添加服务器代码段。
谁能告诉我如何update/add
ngnix
入口控制器的配置?
我得到了上述问题的解决方案。 我用过
nginx.ingress.kubernetes.io/proxy-connect-timeout: "300s"
而不是
nginx.ingress.kubernetes.io/proxy-connect-timeout: "300"
和
nginx.ingress.kubernetes.io/server-snippet
而不是
nginx.ingress.kubernetes.io/configuration-snippet
溶液:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: test-iningress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
nginx.ingress.kubernetes.io/proxy-connect-timeout: "300"
nginx.ingress.kubernetes.io/proxy-read-timeout: "300"
nginx.ingress.kubernetes.io/proxy-body-size: "0"
nginx.ingress.kubernetes.io/client-max-body-size: "0"
nginx.ingress.kubernetes.io/configuration-snippet: |
add_header "Cache-Control" "max-age=0, no-cache, no-store, must-revalidate";
add_header "Pragma" "no-cache";
add_header "Expires" "-1";
spec:
rules:
- host: {{ .Values.ingress.hosts }}
http:
paths:
- path: /ui
backend:
serviceName: sift-ui-service
servicePort: {{ .Values.service.sift_ui.port }}
你还有问题吗?
实际上,我在代理体大小配置上遇到了同样的问题。该值不会对 nginx-ingress-controller pod 生效。
我做了一些研究,找到了以下解决方案:
(before) nginx.ingress.kubernetes.io/proxy-body-size: "0"
(after) ingress.kubernetes.io/proxy-body-size: "0"
我所做的是在注释设置中省略了"nginx"。
我认为您可以尝试按如下方式配置注释:
metadata:
name: test-iningress
annotations:
ingress.kubernetes.io/rewrite-target: /
ingress.kubernetes.io/proxy-connect-timeout: "300s"
ingress.kubernetes.io/proxy-read-timeout: "300s"
ingress.kubernetes.io/client-max-body-size: "0"
希望它适用于您的环境!