我正在设置一个 GCP url 映射,以根据 cookie 值将请求路由到后端服务。由于 cookie 将具有多个键值,因此我正在尝试使用正则表达式匹配器。我需要根据 cookie 中的区域值将请求路由到后端。典型的 cookie 如下所示:foo=bar;region=eu;variant=beta;
defaultService: https://www.googleapis.com/compute/v1/projects/<project_id>/global/backendServices/multi-region-1
kind: compute#urlMap
name: regex-url-map
hostRules:
- hosts:
- '*'
pathMatcher: path-matcher-1
pathMatchers:
- defaultService: https://www.googleapis.com/compute/v1/projects/<project_id>/global/backendServices/multi-region-1
name: path-matcher-1
routeRules:
- matchRules:
- prefixMatch: /
headerMatches:
- headerName: Cookie
regexMatch: (region=us)
priority: 0
service: https://www.googleapis.com/compute/v1/projects/<project_id>/global/backendServices/multi-region-1
- matchRules:
- prefixMatch: /
headerMatches:
- headerName: Cookie
regexMatch: (region=eu)
priority: 1
service: https://www.googleapis.com/compute/v1/projects/<project_id>/global/backendServices/multi-region-2
但是,此 url-map 验证失败并出现以下错误:
$ gcloud compute url-maps validate --source regex-url-map.yaml
result:
loadErrors:
- HttpHeaderMatch has no predicates specified
loadSucceeded: false
testPassed: false
请注意,如果 cookie 值如下所示,则与 cookie 的完全匹配会通过验证并正确匹配region=us
:headerMatches
完全匹配部分如下所示:
headerMatches:
- headerName: Cookie
exactMatch: region=us
关于我在这里做错了什么的任何指示?谢谢!