在 ISTIO VirtualService 和 DestinationRule 中表现不正常,找到下面的清单, 当尝试卷曲我的服务时,即使仅在虚拟服务中提到 v1,它也会将流量分配到 v1 和 v2 pod
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-v1
namespace: istio
labels:
app: nginx
version: v1
spec:
selector:
matchLabels:
app: nginx
version: v1
template:
metadata:
labels:
app: nginx
version: v1
spec:
containers:
- name: nginx
image: chaitanya305/good-morning
ports:
- containerPort: 80
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-v2
namespace: istio
labels:
app: nginx
version: v2
spec:
selector:
matchLabels:
app: nginx
version: v2
template:
metadata:
labels:
app: nginx
version: v2
spec:
containers:
- name: nginx
image: chaitanya305/good-night
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: nginx-svc
namespace: istio
labels:
app: nginx
spec:
selector:
app: nginx
ports:
- port: 80
targetPort: 80
nodePort: 30080
type: NodePort
---
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
name: my-virtualservice
namespace: istio
spec:
hosts:
- nginx-svc.istio.svc.cluster.local
http:
- route:
- destination:
host: nginx-svc.istio.svc.cluster.local
subset: v1
---
apiVersion: networking.istio.io/v1beta1
kind: DestinationRule
metadata:
name: my-destinationrule
namespace: istio
spec:
host: nginx-svc.istio.svc.cluster.local
subsets:
- name: v1
labels:
version: v1
- name: v2
labels:
version: v2
当我尝试访问以下网址时
卷曲 nginx-svc.istio.cluster.local
流量同时流向 v1 和 v2 pod,根据虚拟服务规则,它假定仅流向 v1。应该只提供输出“嗨,早上好”。
root@jenkins-deployment-f4d955ff4-kpxgj:/tmp#cat bash2.sh 虽然是真的 做 卷曲 nginx-svc.istio.svc.cluster.local 睡觉2 完毕 root@jenkins-deployment-f4d955ff4-kpxgj:/tmp# ./bash2.sh
Hi good morning
good Night sweet dreams
Hi good morning
Hi good morning
Hi good morning
good Night sweet dreams
good Night sweet dreams
Hi good morning
^Croot@jenkins-部署-f4d955ff4-kpxgj:/tmp#
您运行curl命令的pod应该有istio-proxy sidecar。仅在源 Pod 中考虑规则。因此源 pod 需要代理 sidecar。如果您没有 nginx-v1 和 nginx-v2 部署的代理,这也将起作用。尽管请求将是明文的。