我正在为一组内部服务实现一些路由逻辑,其中委托 VirtualService 看起来是一个不错的解决方案:
https://istio.io/latest/docs/reference/config/networking/virtual-service/#Delegate
我创建了一些类似于文档中的测试设置,只有一个区别。就我而言,绑定到“网状”网关的“根”VirtualService 和“主机”则是一些内部服务名称。这应该有效还是委派仅适用于非网状网关?
这是根 VirtualService(想法是所有请求都发送到 worker-pool.default.svc.cluster.local
,然后根据某些 HTTP 标头将它们转发到其他 VirtualService):
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: worker-pool
spec:
hosts:
- worker-pool.default.svc.cluster.local
http:
- name: "route 1"
match:
- headers:
customer-id:
exact: alice
delegate:
name: worker-for-alice
- name: "route 2"
match:
- headers:
customer-id:
exact: bob
delegate:
name: worker-for-bob
这里是另一个 VirtualService(只显示一个,两者看起来一样):
apiVersion: v1
kind: Service
metadata:
name: worker-for-alice
labels:
app: worker-for-alice
service: worker-for-alice
spec:
...
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: worker-for-alice
spec:
http:
- route:
- destination:
host: worker-for-alice
答案 0 :(得分:0)
我想有几点需要考虑:
spec:
gateways:
- mesh
hosts:
- worker-pool.default.svc.cluster.local
http:
...
delegate:
name: worker-for-bob
namespace: <some-namespace>
kubectl edit deployment istiod -n istio-system
然后在spec.template.spec.container.env中添加这个env变量