简体   繁体   English

k8s 入口重定向到集群外的端点

[英]k8s ingress redirect to endpoint outside the cluster

I am using google clould, GKE.我正在使用谷歌云,GKE。

I have this example ingress.yaml :我有这个例子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

I need that when user request specific host, like: example-2.gordion.io , to be redirected to other site, outside the cluster, (on other google cluster actually), using nginx.我需要当用户请求特定主机时,例如: example-2.gordion.io ,使用 nginx 重定向到集群外的其他站点(实际上是在其他谷歌集群上)。

Currently I am aware only to the specific annonation nginx.ingress.kubernetes.io/permanent-redirect which seems to be global.目前我只知道特定的annonation nginx.ingress.kubernetes.io/permanent-redirect这似乎是全球性的。 How is it possible to redirct based on specific requested host in this ingress file?如何根据此入口文件中的特定请求主机重定向?

you combine an externalName service with another ingress file: In the following yaml file we define an ExternalName service with the name example-2.gordion.io-service , which will lead to the real site service in the other cluster:您将 externalName 服务与另一个入口文件组合在一起:在以下 yaml 文件中,我们定义了一个名为example-2.gordion.io-serviceExternalName服务,这将导致另一个集群中的真实站点服务:

kind: Service
apiVersion: v1
metadata:
  name: example-2.gordion.io-service
spec:
  type: ExternalName
  externalName: internal-name-of-example-2.gordion.io

And an ingress file to direct example-2.gordion.io to example-2.gordion.io-service :还有一个入口文件将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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM