Dubbo3服务部署到 k8s ,接入 Istio 的流量治理体系(Sidecar模式)
Dubbo版本:Dubbo3实验环境:k8s 版本:1.17.6istio版本: 1.7.3。
·
Dubbo版本:Dubbo3
实验环境:
k8s 版本:1.17.6
istio版本: 1.7.3
一、资源对象的准备
1.创建独立的命名空间,并开启sidecar自动注入
apiVersion: v1
kind: Namespace
metadata:
name: dubbo-demo
labels:
istio-injection: enable #开启sidecar自动注入
2.部署生产者V1(provider-v1)
生产者V1 service
apiVersion: v1
kind: Service
metadata:
name: dubbo-samples-mesh-provider
namespace: dubbo-demo
spec:
type: ClusterIP
sessionAffinity: None
selector:
app: dubbo-samples-mesh-provider
ports:
- name: grpc-tri
port: 50052
targetPort: 50052
生产者V1 deployment
apiVersion: apps/v1
kind: Deployment
metadata:
name: dubbo-samples-mesh-provider-v1
namespace: dubbo-demo
spec:
replicas: 2
selector:
matchLabels:
app: dubbo-samples-mesh-provider
version: v1
template:
metadata:
labels:
app: dubbo-samples-mesh-provider
version: v1
annotations:
sidecar.istio.io/rewriteAppHTTPProbers: "false" # Prevent istio rewrite http probe
spec:
containers:
- name: server
image: apache/dubbo-demo:dubbo-samples-mesh-provider-v1_0.0.1
imagePullPolicy: Always
ports:
- name: grpc-tri
containerPort: 50052
protocol: TCP
- name: http-health
containerPort: 22222
protocol: TCP
livenessProbe:
......
readinessProbe:
......
startupProbe:
......
pod中的两个容器分别如下:其中 server容器为业务容器
3. 部署消费者(consumer)
部署消费者 service
apiVersion: v1
kind: Service
metadata:
name: dubbo-samples-mesh-consumer
namespace: dubbo-demo
spec:
type: ClusterIP
sessionAffinity: None
selector:
app: dubbo-samples-mesh-consumer
ports:
- name: grpc-dubbo
protocol: TCP
port: 50052
targetPort: 50052
部署消费者deployment
apiVersion: apps/v1
kind: Deployment
metadata:
name: dubbo-samples-mesh-consumer
namespace: dubbo-demo
spec:
replicas: 1
selector:
matchLabels:
app: dubbo-samples-mesh-consumer
version: v1
template:
metadata:
labels:
app: dubbo-samples-mesh-consumer
version: v1
annotations:
sidecar.istio.io/rewriteAppHTTPProbers: "false"
spec:
containers:
- name: server
image: hub.guazi-cloud.com/lichun4/dubbo-demo2:v1
imagePullPolicy: Always
ports:
- name: grpc-tri
containerPort: 50052
protocol: TCP
- name: http-health
containerPort: 22222
protocol: TCP
env:
- name: POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
livenessProbe:
......
readinessProbe:
......
startupProbe:
......
pod中的两个容器分别如下:其中 server容器为业务容器
4.部署生产者V2(provider-v2)
provider-v2-deployment
apiVersion: apps/v1
kind: Deployment
metadata:
name: dubbo-samples-mesh-provider-v2
namespace: dubbo-demo
spec:
replicas: 2
selector:
matchLabels:
app: dubbo-samples-mesh-provider
version: v2
template:
metadata:
labels:
app: dubbo-samples-mesh-provider
version: v2
annotations:
sidecar.istio.io/rewriteAppHTTPProbers: "false"
spec:
containers:
- name: server
image: apache/dubbo-demo:dubbo-samples-mesh-provider-v2_0.0.1
imagePullPolicy: Always
ports:
- name: grpc-tri
containerPort: 50052
protocol: TCP
- name: http-health
containerPort: 22222
protocol: TCP
livenessProbe:
......
readinessProbe:
......
startupProbe:
......
5.部署DR、VS
DR:
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
name: dubbo-samples-mesh-provider
namespace: dubbo-demo
spec:
host: dubbo-samples-mesh-provider.dubbo-demo.svc.cluster.local
trafficPolicy:
loadBalancer:
simple: ROUND_ROBIN
subsets:
- name: v1
labels:
version: v1
- name: v2
labels:
version: v2
VS:
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: dubbo-samples-mesh-provider
namespace: dubbo-demo
spec:
hosts:
- dubbo-samples-mesh-provider.dubbo-demo.svc.cluster.local
http:
- route:
- destination:
host: dubbo-samples-mesh-provider.dubbo-demo.svc.cluster.local
subset: v1
port:
number: 50052
weight: 100
- destination:
host: dubbo-samples-mesh-provider.dubbo-demo.svc.cluster.local
subset: v2
port:
number: 50052
weight: 0
二、切流实验
当前VS权重比例 provider-v1:provider-v2 = 100:0
查看消费者业务容器日志
kc logs -f dubbo-samples-mesh-consumer-7778c46d5b-kztl5 -n dubbo-demo -c server
可观察到,消费者仅消费生产者V1生产的数据,符合预期
调整VS权重比例 provider-v1:provider-v2 = 50:50
查看消费者业务容器日志
可观察到,消费者既消费生产者V1的数据,又消费生产者V2的数据,比率大概为1:1,符合预期
注意:示例中,生产者消费者都属于同一个namespace;如果需要调用不同的namespace的提供者,需要按如下配置(dubbo版本>=3.1.2):
注解方式:
@DubboReference(providedBy = "istio-demo-dubbo-producer",providerPort = 20885, providerNamespace = "istio-demo")
xml方式:
<dubbo:reference id="demoService" check="true"
interface="org.apache.dubbo.samples.basic.api.DemoService"
provider-port="20885"
provided-by="istio-dubbo-producer"
provider-namespace="istio-demo"/>
注:参考文章进行实验:Dubbo proxy mesh using Envoy & Istio | Apache Dubbo
更多推荐
已为社区贡献9条内容
所有评论(0)