目录
Nginx Ingress 注解使用在 Ingress 资源实例中,IIngress 可以理解就是nginx,作为nginx当然可以对接收到的流量做一些处理
--ingress-class=ingress-other
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: other-ngx-k8s
namespace: other-ngx
annotations:
kubernetes.io/ingress.class: "ingress-other"
spec:
rules:
- host: pyenv.cc
http:
paths:
- path: /
backend:
serviceName: golang-pyenv-cc
servicePort: 9001
nginx.ingress.kubernetes.io/force-ssl-redirect: "true"
通过这个annotation可以强制 https,如果是http请求,会通过 301 redirect到 httpsapiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: test-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
nginx.ingress.kubernetes.io/force-ssl-redirect: "true"
nginx.ingress.kubernetes.io/ssl-redirect: "true"
nginx.ingress.kubernetes.io/preserve-trailing-slash: "true"
spec:
rules:
- http:
paths:
- path: /testpath
backend:
serviceName: test
servicePort: 80
nginx.org/proxy-connect-timeout 和nginx.org/proxy-read-timeout
这两个参数分别设置nginx的建立连接以及等待结果的超时时间apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: cafe-ingress-with-annotations
annotations:
nginx.org/proxy-connect-timeout: "30s"
nginx.org/proxy-read-timeout: "20s"
spec:
rules:
- host: demp.example.com
http:
paths:
- path: /tea
backend:
serviceName: tea-svc
servicePort: 80
- path: /coffee
backend:
serviceName: coffee-svc
servicePort: 80
nginx.ingress.kubernetes.io/cors-allow-methods
设置支持跨域请求的方法。apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: test-ingress
annotations:
nginx.ingress.kubernetes.io/enable-cors: "true"
nginx.ingress.kubernetes.io/cors-allow-methods: "PUT, GET, POST, OPTIONS"
nginx.ingress.kubernetes.io/cors-allow-headers: "X-Forwarded-For, X-app123-XPTO"
nginx.ingress.kubernetes.io/cors-expose-headers: "*, X-CustomResponseHeader"
nginx.ingress.kubernetes.io/cors-max-age: 600
nginx.ingress.kubernetes.io/cors-allow-credentials: "false"
spec:
rules:
- http:
paths:
- path: /testpath
backend:
serviceName: test
servicePort: 80
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: test-ingress
annotations:
nginx.ingress.kubernetes.io/limit-rps: "5"
nginx.ingress.kubernetes.io/limit-rpm: "300"
nginx.ingress.kubernetes.io/limit-connections: "10"
spec:
rules:
- http:
paths:
- path: /testpath
backend:
serviceName: test
servicePort: 80
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: test-ingress
annotations:
nginx.ingress.kubernetes.io/proxy-body-size: 8m
spec:
rules:
- http:
paths:
- path: /testpath
backend:
serviceName: test
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: test-ingress
annotations:
ingress.kubernetes.io/whitelist-source-range: "10.1.0.0/24,172.10.0.1"
spec:
rules:
- http:
paths:
- path: /testpath
backend:
serviceName: test
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: test-ingress
annotations:
nginx.ingress.kubernetes.io/default-backend:
spec:
rules:
- http:
paths:
- path: /testpath
backend:
serviceName: test
nginx.ingress.kubernetes.io/enable-access-log
设置成falseapiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: test-ingress
annotations:
nginx.ingress.kubernetes.io/enable-access-log: "false"
spec:
rules:
- http:
paths:
- path: /testpath
backend:
serviceName: test
kind: Ingress
metadata:
annotations:
nginx.ingress.kubernetes.io/server-snippet: |-
add_header Shy-Test 888;
more_set_headers 'Shy-Hello: hello' 'Demo: demo';
labels:
cattle.io/creator: norman
name: website-muses-docs
namespace: muses-docs
nginx.ingress.kubernetes.io/configuration-snippet: |
more_set_headers "Request-Id: $req_id";
nginx.ingress.kubernetes.io/configuration-snippet: |
proxy_set_header My-Custom-Header $http_my_custom_header;