google-cloud-run - 将一个自定义域映射到多个服务的正确方法是什么?
问题描述
使用 GKE 和 Cloud Run映射自定义域的说明适用于 1:1 域:服务映射。但是如果我想拥有 1:M domain:services 并与 URI 匹配,
myapp.com/login >> login-service
myapp.com/logout >> logout-service
我试过的
第二个域映射创建语句将出错,因为域在服务中必须是唯一的:
$ gcloud beta run domain-mappings create --service login-service --domain myapp.com --cluster mycluster --cluster-location europe-west2-a
Creating......done.
RECORD TYPE CONTENTS
A XX.XXX.XXX.XX
$ gcloud beta run domain-mappings create --service login-service --domain myapp.com --cluster mycluster --cluster-location europe-west2-a
ERROR: ... "message": domainmappings.domains.cloudrun.com \"myapp.com\" already exists ...
以前,当使用手动创建的 Knative 环境时,我可以使用 Istio 来实现VirtualService
:
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: entry-route
namespace: default
spec:
- knative-ingress-gateway.knative-serving.svc.cluster.local
# Set host to the domain name that you own.
hosts:
- myapp.com
http:
- match:
- uri:
prefix: "/login"
rewrite:
authority: login-service.default.myapp.com
route:
- destination:
host: knative-ingressgateway.istio-system.svc.cluster.local
weight: 100
- match:
- uri:
prefix: "/logout"
rewrite:
authority: logout-service.default.myapp.com
route:
- destination:
host: knative-ingressgateway.istio-system.svc.cluster.local
weight: 100
但是,虽然我可以通过 Cloud Run 在 GKE 上应用它,但所有内容都被路由到映射到域的服务。
我还尝试删除gcloud beta run domain-mappings
创建的,将istio-ingressgateway
LoadBalancer 设置为保留的静态 IP,并将我的域指向 LoadBalancer。但是,这只会导致503s
.
为什么我不能只指向istio-ingressgateway
LoadBalancer 并VirtualService
为我提供一条路线?
解决方案
Firebase Hosting 与 Cloud Run的集成允许您将不同的子路径重写到不同的 Cloud Run 服务。配置看起来像:
{
"hosting": {
"rewrites": [
{"source": "/api/**", "run": {"serviceId": "api"}},
{"source": "/charts/*.svg", "run": {"serviceId": "chartgen"}},
{"source": "**", "run": {"serviceId": "ssr"}}
]
}
}
推荐阅读
- python - 使用 Python 检测并可能定位图像中的勾选框(光学标记识别)
- pyspark - Pyspark:withColumn 查找列,但条件告诉它不要这样做
- javascript - babel + core-js + webpack 使代码支持旧版 chrome,许多 node_modules 文件引发“export ... was not found”错误
- firebase - 如何在登录期间检查用户并将其发送到不同的主页
- installation - pygame 安装在 mac 但命令“import pygame”没有向我报告“>>>”
- sql - 查找数字是否重复超过 4 次 - ORACLE SQL
- powershell - 如何使用 curl 和 windows powershell 设置 cookie?
- wordpress - 购物车页面 woocommerce 未更新
- flutter - 如何在颤振(飞镖)中生成 x-wsse 标头?
- java - 如何将数据转换为结果
jooq中的数据类型