正在将流量重定向到外部url



基于注释的更新:

假设在另一个GCP项目中有一个API托管@hello.com.pany1.com。。。

我想有一种可能性,当某人1访问url-abc.company.com时,他们是来自hello.com.company1.com的服务器流量,类似于API网关。。。

使用API网关可以很容易地完成,我只是想弄清楚是否可以使用K8S服务&进入。


我已经创建了一个云DNS区域作为abc.company.com

当有人访问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

可以实现您想要的,但您需要使用Nginx Ingress来实现,因为您需要使用特定的注释-Nginx.Ingress.kubernetes.io/upstream-vhost.

它在这个基于storage.googleapis.com的Github问题中得到了很好的描述。

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.ingress.kubernetes.io/backend-protocol: "HTTPS"

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

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

最新更新