我目前正在处理一个案例,当我们需要动态创建服务并通过主网关的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是否有一种机制来指定带有如下变量/参数的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的消耗而言,保留它们是否昂贵?
提前谢谢!
如何在Istio VirtualService中使用变量?
据我所知,istio中没有这样的选项来指定前缀和主机中的变量,如果它只是一个前缀,那么你可以尝试使用regex而不是前缀。
如果你想以某种方式自动化它,我的意思是创建一个变量并同时输入前缀和主机,那么你可以尝试用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
成千上万的VS将如何影响请求处理的性能?
正如@lanceliuu提到的那样,这是一个github问题
当我们在单个集群中创建约1k个虚拟服务时,入口网关会缓慢地获取新的虚拟服务。
因此,这可能是数千个虚拟服务的问题之一。
就CPU和RAM的消耗而言,保留它们是否昂贵?
我认为这需要测试。我查看了上面的github问题,他们提到istio组件没有mem/cpu压力,但我不能说这有多贵。
理论上,您可以创建一个大型虚拟服务,而不是数千个,但正如文档中所提到的,您应该将大型虚拟服务拆分为多个资源。
其他资源:
- https://engineering.hellofresh.com/everything-we-learned-running-istio-in-production-part-2-ff4c26844bfb
- https://istio.io/latest/docs/ops/deployment/performance-and-scalability/
- https://perf.dashboard.istio.io/