gpt4 book ai didi

nginx - k8s ingress 重定向到集群外的端点

转载 作者:行者123 更新时间:2023-12-02 12:02:55 25 4
gpt4 key购买 nike

我正在使用谷歌云、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 重定向到集群外部的其他站点(实际上在其他 google 集群上) .

目前我只知道特定的注释 nginx.ingress.kubernetes.io/permanent-redirect 这似乎是全局的。如何根据此入口文件中的特定请求主机进行重定向?

最佳答案

您将 externalName 服务与另一个入口文件组合:在下面的 yaml 文件中,我们定义了一个 ExternalName。名为 example-2.gordion.io-service 的服务,这将导致另一个集群中的真实站点服务:

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

关于nginx - k8s ingress 重定向到集群外的端点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58489453/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com