将流量重定向到外部 url

Nik*_*pta 6 google-cloud-platform google-cloud-dns google-kubernetes-engine

根据评论更新:

假设另一个 GCP 项目中有一个托管于 @ hello.company1.com 的 API...

我希望有一种可能性,当 some1 访问 url abc.company.com 时,它们会处理来自 hello.company1.com 的流量,类似于 API 网关...

使用 API 网关可以轻松完成此操作,我只是想弄清楚是否可以使用 K8S 服务和入口。


我已创建一个 Cloud DNS 区域作为 abc.company.com

当有人访问 abc.company.com/google 时,我希望将请求转发到外部网址(假设为 google.com)

是否可以通过创建外部名称类型的服务和主机名为 abc.company.com 的入口来实现

kind: Service
apiVersion: v1
metadata:
  name: test-srv
spec:
  type: ExternalName
  externalName: google.com

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: test-ingress
spec:
  rules:
  - host: abc.company.com
  - http:
      paths:
      - path: /google
        backend:
          serviceName: test-srv
Run Code Online (Sandbox Code Playgroud)

Pjo*_*erS 8

可以实现您想要的,但是您需要使用Nginx Ingress来做到这一点,因为您需要使用特定的注释 - nginx.ingress.kubernetes.io/upstream-vhost

在这个基于 的Github 问题中对此进行了很好的描述storage.googleapis.com

apiVersion: v1
kind: Service
metadata:
  name: google-storage-buckets
spec:
  type: ExternalName
  externalName: storage.googleapis.com
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: proxy-assets-ingress
  annotations:
    kubernetes.io/ingress.class: nginx-ingress
    nginx.ingress.kubernetes.io/rewrite-target: /[BUCKET_NAME]/[BUILD_SHA]
    nginx.ingress.kubernetes.io/backend-protocol: "HTTPS"
    nginx.ingress.kubernetes.io/upstream-vhost: "storage.googleapis.com"
spec:
  rules:
  - host: abc.company.com
    http:
      paths:
      - path: /your/path
        backend:
          serviceName: google-storage-buckets
          servicePort: 443
Run Code Online (Sandbox Code Playgroud)

取决于您的需求,如果您要在非 https 上使用它,您需要更改servicePort80并删除注释nginx.ingress.kubernetes.io/backend-protocol: "HTTPS"

有关更多详细信息,您可以查看其他类似Stackoverflow 问题

请记住不要在同一个清单中使用-inspec.rules.host和 in spec.rules.http。如果您的配置中没有,则应-仅使用 , 。httphost