Kubernetes 如何使用istio在应用程序版本之间进行负载平衡时使用子集?
我有以下服务:Kubernetes 如何使用istio在应用程序版本之间进行负载平衡时使用子集?,kubernetes,load-balancing,istio,Kubernetes,Load Balancing,Istio,我有以下服务: apiVersion: v1 kind: Service metadata: name: downstream-service spec: type: ClusterIP selector: app: downstream ports: - protocol: TCP port: 80 targetPort: 80 我希望基于应用程序版本进行负载平衡,我在部署中定义如下: apiVersion: apps/v1 kind:
apiVersion: v1
kind: Service
metadata:
name: downstream-service
spec:
type: ClusterIP
selector:
app: downstream
ports:
- protocol: TCP
port: 80
targetPort: 80
我希望基于应用程序版本进行负载平衡,我在部署中定义如下:
apiVersion: apps/v1
kind: Deployment
metadata:
name: downstream-deployment-v1
labels:
app: downstream
version: v1
spec:
replicas: 1
selector:
matchLabels:
app: downstream
version: v1
template:
metadata:
labels:
app: downstream
version: v1
spec:
containers:
- name: downstream
image: downstream:0.1
ports:
- containerPort: 80
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: downstream-deployment-v2
labels:
app: downstream
version: v2
spec:
replicas: 1
selector:
matchLabels:
app: downstream
version: v2
template:
metadata:
labels:
app: downstream
version: v2
spec:
containers:
- name: downstream
image: downstream:0.2
ports:
- containerPort: 80
现在,这两种部署上的流量都按预期的50/50进行路由,但我想根据我定义的DestinationRule和VirtualService调整权重:
但我还是得到了50/50的分成
我曾尝试用下游服务替换down-service.svc.cluster.local,但结果是,如果yaml中没有定义权重,并且删除了子集,我将得到50/50的拆分,但是当我添加了没有权重的子集时,我将得到v1实例上的所有流量
我做错了什么
编辑
这可能是原因,但我不确定该怎么做:
$ istioctl x describe service downstream-service
Service: downstream-service
Port: 80/auto-detect targets pod port 80
DestinationRule: downstream-service for "downstream-service"
Matching subsets: v1,v2
No Traffic Policy
VirtualService: downstream-route
2 HTTP route(s)
$ istioctl x describe pod downstream-deployment-v2-69bdfc8fbf-bm22f
Pod: downstream-deployment-v2-69bdfc8fbf-bm22f
Pod Ports: 80 (downstream), 15090 (istio-proxy)
--------------------
Service: downstream-service
Port: 80/auto-detect targets pod port 80
DestinationRule: downstream-service for "downstream-service"
Matching subsets: v2
(Non-matching subsets v1)
No Traffic Policy
VirtualService: downstream-route
1 additional destination(s) that will not reach this pod
Route to non-matching subset v1 for (everything)
$ istioctl x describe pod downstream-deployment-v1-65bd866c47-66p9k
Pod: downstream-deployment-v1-65bd866c47-66p9k
Pod Ports: 80 (downstream), 15090 (istio-proxy)
--------------------
Service: downstream-service
Port: 80/auto-detect targets pod port 80
DestinationRule: downstream-service for "downstream-service"
Matching subsets: v1
(Non-matching subsets v2)
No Traffic Policy
VirtualService: downstream-route
1 additional destination(s) that will not reach this pod
Route to non-matching subset v2 for (everything)
编辑2
所以我推出kiali就是为了看看:
假设重量为100,因为只有一个路线目的地
但不知道如何解决这个问题。好的,看来我漏掉了一个很大的错误,那就是有许多目的地的路由是加权的,而不是有许多加权路由的http 因此,我的VirtualService的正确版本如下:
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
name: downstream-service
spec:
hosts:
- downstream-service
http:
- name: "downstream-service-routes"
route:
- destination:
host: downstream-service
subset: v1
weight: 10
- destination:
host: downstream-service
subset: v2
weight: 90
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
name: downstream-service
spec:
hosts:
- downstream-service
http:
- name: "downstream-service-routes"
route:
- destination:
host: downstream-service
subset: v1
weight: 10
- destination:
host: downstream-service
subset: v2
weight: 90