Google cloud platform 将流量重定向到外部url
基于评论的更新: 假设在另一个GCP项目中有一个托管在@hello.company1.com上的API 我希望有一种可能性,当某人访问一个url abc.company.com时,他们是来自hello.company1.com的服务器流量,类似于API网关 使用API网关很容易做到,我只是想弄清楚是否可以使用K8S服务和入口Google cloud platform 将流量重定向到外部url,google-cloud-platform,google-kubernetes-engine,google-cloud-dns,Google Cloud Platform,Google Kubernetes Engine,Google Cloud Dns,基于评论的更新: 假设在另一个GCP项目中有一个托管在@hello.company1.com上的API 我希望有一种可能性,当某人访问一个url abc.company.com时,他们是来自hello.company1.com的服务器流量,类似于API网关 使用API网关很容易做到,我只是想弄清楚是否可以使用K8S服务和入口 我已经创建了一个名为abc.company.com的云DNS区域 kind: Service apiVersion: v1 metadata: name: test-
我已经创建了一个名为abc.company.com的云DNS区域
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
当有人访问abc.company.com/google时,我希望将请求转发到外部url,比如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
实现您想要的是可能的,但是您需要使用,因为您需要使用特定的注释- 在基于
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
根据您的需要,如果要在非https上使用它,您需要将servicePort
更改为80
并删除注释nginx.ingres.kubernetes.io/backend-protocol:“https”
有关更多详细信息,您可以查看其他类似的Stackoverflow
请记住不要在同一清单中使用
spec.rules.host
和spec.rules.http
中的-
。如果您的配置中没有主机
,则只应将-
与http
一起使用。可以实现您想要的功能,但是您需要使用,因为您需要使用特定的注释-
在基于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
根据您的需要,如果要在非https上使用它,您需要将servicePort
更改为80
并删除注释nginx.ingres.kubernetes.io/backend-protocol:“https”
有关更多详细信息,您可以查看其他类似的Stackoverflow
请记住不要在同一清单中使用
spec.rules.host
和spec.rules.http
中的-
。如果您的配置中没有主机
,则只能将-
与http
一起使用。DNS服务器对URL一无所知。DNS服务器只处理域名。如果您的目标是重写URL,则需要在接收端点运行一个服务来将客户端重定向到新位置。对于大多数web服务器(如Apache或Nginx),这是很容易做到的。另一种选择是在域前面使用配置了URL映射的负载平衡器。@JohnHanley可能是我不应该在我的问题中使用重定向这个词。。。我的目标是,当有人访问abc.mycompany/test-api时,他们实际上收到了test-api.mycompany.com的内容。你需要代理还是重定向?@guillaumeblaquiere proxy…你能详细说明你的问题吗(同时附上评论中的信息)?所以你想将trafic重定向到特定的服务(在这个集群或其他集群内,云?)来执行一些脚本?DNS服务器对URL一无所知。DNS服务器只处理域名。如果您的目标是重写URL,则需要在接收端点运行一个服务来将客户端重定向到新位置。对于大多数web服务器(如Apache或Nginx),这是很容易做到的。另一种选择是在域前面使用配置了URL映射的负载平衡器。@JohnHanley可能是我不应该在我的问题中使用重定向这个词。。。我的目标是,当有人访问abc.mycompany/test-api时,他们实际上收到了test-api.mycompany.com的内容。你需要代理还是重定向?@guillaumeblaquiere proxy…你能详细说明你的问题吗(同时附上评论中的信息)?所以您想将trafic重定向到特定的服务(在这个集群或其他集群内,云?)来执行一些脚本?