如何更新ngnix入口控制器的ngnix配置

时间:2018-08-24 11:17:03

标签: kubernetes-ingress nginx-ingress

我已使用头盔图表在ngnix上安装了K8 cluster入口控制器。

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时

kubectl exec -it nginx-ingress-controller-b4477bdf7-gwt8v -n kube-system -- cat /etc/nginx/nginx.conf

proxy-connect-timeoutproxy-read-timeout未更新。它显示默认值,也不会添加服务器代码段。

谁能告诉我如何update/add配置ngnix入口控制器?

2 个答案:

答案 0 :(得分:0)

您还有问题吗?

实际上,我在proxy-body-size配置上也遇到了同样的问题。该值对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"

希望它在您的环境中有效!

答案 1 :(得分:0)

我已经解决了上述问题。 我用过

 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 }}