[英]k8s ingress redirect to endpoint outside the cluster
我正在使用谷歌雲,GKE。
我有這個例子ingress.yaml
:
1 apiVersion: extensions/v1beta1
2 kind: Ingress
3 metadata:
4 name: kuard
5 namespace: sample
6 annotations:
7 kubernetes.io/ingress.class: "nginx"
8 cert-manager.io/issuer: "letsencrypt-prod"
9 nginx.ingress.kubernetes.io/permanent-redirect: https://www.google.com
10 spec:
11 tls:
12 - hosts:
13 - example.gordion.io
14 secretName: quickstart-example-tls
15 rules:
16 - host: example.gordion.io
17 http:
18 paths:
19 - path: /
20 backend:
21 serviceName: kuard
22 servicePort: 80
我需要當用戶請求特定主機時,例如: example-2.gordion.io
,使用 nginx 重定向到集群外的其他站點(實際上是在其他谷歌集群上)。
目前我只知道特定的annonation nginx.ingress.kubernetes.io/permanent-redirect
這似乎是全球性的。 如何根據此入口文件中的特定請求主機重定向?
您將 externalName 服務與另一個入口文件組合在一起:在以下 yaml 文件中,我們定義了一個名為example-2.gordion.io-service
的ExternalName服務,這將導致另一個集群中的真實站點服務:
kind: Service
apiVersion: v1
metadata:
name: example-2.gordion.io-service
spec:
type: ExternalName
externalName: internal-name-of-example-2.gordion.io
還有一個入口文件將example-2.gordion.io
指向example-2.gordion.io-service
:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: example-ingress
annotations:
kubernetes.io/ingress.class: "nginx"
spec:
rules:
- host: example-2.gordion.io
http:
paths:
- path: /
backend:
serviceName: example-2.gordion.io-service
servicePort: 80
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.