nginx-ingress-controller部署配置詳解
引言
- 開源
Nginx Ingress Controller(k8s 官網(wǎng)推薦)、Nginx Incorporaton (nginx inc,nginx官網(wǎng)) 和 Nginx Incorporaton Plus - 當(dāng)多個(gè)ingress對(duì)象資源配置同一個(gè)主機(jī)時(shí),就會(huì)發(fā)生主機(jī)沖突。
Ingress Controller支持兩種處理主機(jī)沖突的選項(xiàng):
- Choosing the Winner
If multiple resources contend for the same host, the Ingress Controller will pick the winner based on the creationTimestamp of the resources: the oldest resource will win. In case there are more than one oldest resources (their creationTimestamp is the same), the Ingress Controller will choose the resource with the lexicographically smallest uid.
- Merging Configuration for the Same Host
It is possible to merge configuration for multiple Ingress resources for the same host. One common use case for this approach is distributing resources across multiple namespaces.
- 所以最好一個(gè)域名,對(duì)應(yīng)一個(gè)ingress對(duì)象
# describe ingress 報(bào)錯(cuò) Warning Rejected 17m (x2 over 6d23h) nginx-ingress-controller All hosts are taken by other resources Warning Rejected 17m (x2 over 3d17h) nginx-ingress-controller All hosts are taken by other resources
一. 部署
wget https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.2.1/deploy/static/provider/cloud/deploy.yaml
# 選擇版本
https://github.com/kubernetes/ingress-nginx/blob/controller-v1.4.0/deploy/static/provider/cloud/deploy.yaml
# 修改yaml中的image,改為自己的
# 可用國(guó)內(nèi)源: registry.cn-hangzhou.aliyuncs.com/google_containers/nginx-ingress-controller:v1.2.1
registry.cn-hangzhou.aliyuncs.com/google_containers/nginx-ingress-controller:v1.8.1
registry.cn-hangzhou.aliyuncs.com/google_containers/kube-webhook-certgen:v20230407二. 配置
1. 跨域
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: front-web
namespace: web
annotations:
kubernetes.io/ingress.class: "nginx"
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: "Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control"
nginx.ingress.kubernetes.io/cors-expose-headers: "*, X-CustomResponseHeader"
nginx.ingress.kubernetes.io/cors-max-age: 6002. 白名單
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress-myapp
namespace: default
annotations:
kubernetes.io/ingress.class: "nginx"
# 白名單
nginx.ingress.kubernetes.io/whitelist-source-range: 120.176.65.13,120.79.18.35# 設(shè)置從代理服務(wù)器讀取響應(yīng)的超時(shí)時(shí)間(以秒為單位,默認(rèn)值60) nginx.ingress.kubernetes.io/proxy-read-timeout: "300" # 強(qiáng)制重定向到 HTTPS(即使 Ingress 未啟用 TLS) nginx.ingress.kubernetes.io/force-ssl-redirect: "true"
3. 強(qiáng)制https
apiVersion: networking.k8s.io/v1
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: 804. 跳轉(zhuǎn)
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: test-ingress
namespace: uf
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
ingressClassName: nginx-ingress
rules:
- host: dev-gf.uf.net.cn
http:
paths:
- backend:
service:
name: uf-epi-html
port:
number: 80
path: /epi/(.*)
pathType: ImplementationSpecific以上就是nginx-ingress-controller部署配置詳解的詳細(xì)內(nèi)容,更多關(guān)于nginx ingress controller部署配置的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
封80端口應(yīng)對(duì)策略 Nginx反向代理For WIN2003超級(jí)傻瓜式配置
封80應(yīng)對(duì)策略,Nginx反向代理ForWIN2003超級(jí)傻瓜式配置!2010-03-03
升級(jí)nginx支持HTTP/2服務(wù)端推送的方法
這篇文章主要介紹了升級(jí)nginx支持HTTP/2服務(wù)端推送的方法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-05-05
nginx設(shè)置上傳目錄無執(zhí)行權(quán)限的方法
在windows+iis下,可以設(shè)置上傳目錄,類似:upload,uploadfile,attachments,這樣的目錄下面無腳本執(zhí)行權(quán)限,從而防止非法用戶上傳腳本得到webshell2010-11-11
在Nginx中增加對(duì)OAuth協(xié)議的支持的教程
這篇文章主要介紹了在Nginx中增加對(duì)OAuth協(xié)議的支持的教程,OAuth協(xié)議如今廣泛用于社交網(wǎng)絡(luò)的API中,需要的朋友可以參考下2015-06-06

