如何在 Istio VirtualService 中使用变量?
How to use variables in Istio VirtualService?
我目前正在处理一个案例,当我们需要动态创建服务并通过主网关的 URI 子路径提供对它们的访问时。
我打算使用虚拟服务为他们进行流量路由。特定服务的虚拟服务应如下所示:
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: subpaths-routes
spec:
hosts:
- mainservice.prod.svc.cluster.local
http:
- name: "subpath-redirection"
match:
- uri:
prefix: "/bservices/svc-2345-6789"
route:
- destination:
host: svc-2345-6789.prod.svc.cluster.local
但是这样的服务可能有很多(比如几千个)。都遵循相同的路由模式。
我想知道 Istio 是否有一种机制来指定带有 variables/parameters 的 VirtualService,如下所示:
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: subpaths-routes
spec:
hosts:
- mainservice.prod.svc.cluster.local
http:
- name: "subpath-redirection"
match:
- uri:
prefix: "/bservices/"{{ variable }}
route:
- destination:
host: {{ variable }}.prod.svc.cluster.local
在 Nginx 中,可以通过指定如下内容来做类似的事情:
location ~ /service/(?<variable>[0-9a-zA-Z\_\-]+)/ {
proxy_pass http://$variable:8080;
}
Istio 有没有办法做到这一点?
如果没有,成千上万的 VS 将如何影响请求处理的性能?就 CPU 和消耗的 RAM 而言,保留它们是否昂贵?
提前致谢!
How to use variables in Istio VirtualService?
据我所知,在 istio 中没有这样的选项来指定前缀和主机中的变量,如果它只是一个前缀,那么你可以尝试使用 regex 而不是前缀。
如果您想以某种方式使其自动化,我的意思是创建一个变量并将其放入前缀和主机中,然后您可以尝试使用 helm。
helm 中虚拟服务的例子很少。
- https://github.com/streamsets/helm-charts/blob/master/incubating/control-hub/templates/istio-gateway-virtualservice.yaml
- https://github.com/salesforce/helm-starter-istio/blob/master/templates/virtualService.yaml
how would thousands of VSs impact the performance of request processing?
正如@lanceliuu 在那里提到的那样github issue
When we create ~1k virtualservices in a single cluster, the ingress gateway is picking up new virtualservice slowly.
所以这可能是数以千计的虚拟服务的问题之一。
Is It expensive to keep them in terms of CPU and RAM being consumed?
我会说这需要测试。我检查了上面的 github 问题,他们提到 istio 组件没有 mem/cpu 压力,但我不能说那有多贵。
理论上您可以创建 1 个大型虚拟服务而不是数千个,但如 documentation 中所述,您应该将大型虚拟服务拆分为多个资源。
其他资源:
我目前正在处理一个案例,当我们需要动态创建服务并通过主网关的 URI 子路径提供对它们的访问时。
我打算使用虚拟服务为他们进行流量路由。特定服务的虚拟服务应如下所示:
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: subpaths-routes
spec:
hosts:
- mainservice.prod.svc.cluster.local
http:
- name: "subpath-redirection"
match:
- uri:
prefix: "/bservices/svc-2345-6789"
route:
- destination:
host: svc-2345-6789.prod.svc.cluster.local
但是这样的服务可能有很多(比如几千个)。都遵循相同的路由模式。 我想知道 Istio 是否有一种机制来指定带有 variables/parameters 的 VirtualService,如下所示:
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: subpaths-routes
spec:
hosts:
- mainservice.prod.svc.cluster.local
http:
- name: "subpath-redirection"
match:
- uri:
prefix: "/bservices/"{{ variable }}
route:
- destination:
host: {{ variable }}.prod.svc.cluster.local
在 Nginx 中,可以通过指定如下内容来做类似的事情:
location ~ /service/(?<variable>[0-9a-zA-Z\_\-]+)/ {
proxy_pass http://$variable:8080;
}
Istio 有没有办法做到这一点? 如果没有,成千上万的 VS 将如何影响请求处理的性能?就 CPU 和消耗的 RAM 而言,保留它们是否昂贵?
提前致谢!
How to use variables in Istio VirtualService?
据我所知,在 istio 中没有这样的选项来指定前缀和主机中的变量,如果它只是一个前缀,那么你可以尝试使用 regex 而不是前缀。
如果您想以某种方式使其自动化,我的意思是创建一个变量并将其放入前缀和主机中,然后您可以尝试使用 helm。
helm 中虚拟服务的例子很少。
- https://github.com/streamsets/helm-charts/blob/master/incubating/control-hub/templates/istio-gateway-virtualservice.yaml
- https://github.com/salesforce/helm-starter-istio/blob/master/templates/virtualService.yaml
how would thousands of VSs impact the performance of request processing?
正如@lanceliuu 在那里提到的那样github issue
When we create ~1k virtualservices in a single cluster, the ingress gateway is picking up new virtualservice slowly.
所以这可能是数以千计的虚拟服务的问题之一。
Is It expensive to keep them in terms of CPU and RAM being consumed?
我会说这需要测试。我检查了上面的 github 问题,他们提到 istio 组件没有 mem/cpu 压力,但我不能说那有多贵。
理论上您可以创建 1 个大型虚拟服务而不是数千个,但如 documentation 中所述,您应该将大型虚拟服务拆分为多个资源。
其他资源: