什麼是Ingress
Ingress可以将Kubernetes内部的Service通過HTTP/HTTPS的虛拟主機方式暴露到叢集外部,可以由Ingress定義請求的路由規則。
Ingress 基礎操作
通過資源定義清單建立Ingress
kubectl apply -f nginx-ingress.yaml
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: nginx-ingress
spec:
rules:
- host: nginx.com
http:
paths:
- backend:
serviceName: nginx-service
servicePort: 80
path: /
tls:
- hosts:
- nginx.com
secretName: ingress-certificate
檢視ingress詳細資訊
kubectl get ingress -o yaml

kubectl describe ingress nginx-ingress
Ingress開啟TLS支援
在建立Ingress可以通過spec.tls字段可以啟用TLS,TLS的密鑰對資訊可以通過Secret進行存儲。
tls:
- hosts:
- nginx.com
secretName: ingress-certificate
Ingress相關參數
在Ingress可以配置特定的能力,例如後端的負載權重,負載均衡算法,持久化會話,連接配接逾時時長,開啟WebSocket等。
連接配接性相關的
annotations:
nginx.ingress.kubernetes.io/proxy-connect-timeout: '6000'
nginx.ingress.kubernetes.io/proxy-read-timeout: '6000'
nginx.ingress.kubernetes.io/proxy-send-timeout: '6000'
開啟WebSocket支援
annotations:
nginx.org/websocket-services: teamcity-server-service
更多請參考
https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/annotations/使用技巧
1、安全性考慮建議不要不指定host,所有ingress對象都必須指定host配置,這将保證到一定的安全性。
2、安全性考慮建議開啟全站的TLS,多域名的證書可以使用通配符或者多域名內建一張的證書。