当前位置:   article > 正文

Dubbo3服务部署到 k8s ,接入 Istio 的流量治理体系(Sidecar模式)_dubbo k8s

dubbo k8s

Dubbo版本:Dubbo3

实验环境:

k8s 版本:1.17.6

istio版本: 1.7.3

一、资源对象的准备

1.创建独立的命名空间,并开启sidecar自动注入

  1. apiVersion: v1
  2. kind: Namespace
  3. metadata:
  4. name: dubbo-demo
  5. labels:
  6. istio-injection: enable #开启sidecar自动注入

2.部署生产者V1(provider-v1)

生产者V1 service

  1. apiVersion: v1
  2. kind: Service
  3. metadata:
  4. name: dubbo-samples-mesh-provider
  5. namespace: dubbo-demo
  6. spec:
  7. type: ClusterIP
  8. sessionAffinity: None
  9. selector:
  10. app: dubbo-samples-mesh-provider
  11. ports:
  12. - name: grpc-tri
  13. port: 50052
  14. targetPort: 50052

生产者V1 deployment

  1. apiVersion: apps/v1
  2. kind: Deployment
  3. metadata:
  4. name: dubbo-samples-mesh-provider-v1
  5. namespace: dubbo-demo
  6. spec:
  7. replicas: 2
  8. selector:
  9. matchLabels:
  10. app: dubbo-samples-mesh-provider
  11. version: v1
  12. template:
  13. metadata:
  14. labels:
  15. app: dubbo-samples-mesh-provider
  16. version: v1
  17. annotations:
  18. sidecar.istio.io/rewriteAppHTTPProbers: "false" # Prevent istio rewrite http probe
  19. spec:
  20. containers:
  21. - name: server
  22. image: apache/dubbo-demo:dubbo-samples-mesh-provider-v1_0.0.1
  23. imagePullPolicy: Always
  24. ports:
  25. - name: grpc-tri
  26. containerPort: 50052
  27. protocol: TCP
  28. - name: http-health
  29. containerPort: 22222
  30. protocol: TCP
  31. livenessProbe:
  32. ......
  33. readinessProbe:
  34. ......
  35. startupProbe:
  36. ......

pod中的两个容器分别如下:其中 server容器为业务容器

3. 部署消费者(consumer)

部署消费者 service

  1. apiVersion: v1
  2. kind: Service
  3. metadata:
  4. name: dubbo-samples-mesh-consumer
  5. namespace: dubbo-demo
  6. spec:
  7. type: ClusterIP
  8. sessionAffinity: None
  9. selector:
  10. app: dubbo-samples-mesh-consumer
  11. ports:
  12. - name: grpc-dubbo
  13. protocol: TCP
  14. port: 50052
  15. targetPort: 50052

 部署消费者deployment

  1. apiVersion: apps/v1
  2. kind: Deployment
  3. metadata:
  4. name: dubbo-samples-mesh-consumer
  5. namespace: dubbo-demo
  6. spec:
  7. replicas: 1
  8. selector:
  9. matchLabels:
  10. app: dubbo-samples-mesh-consumer
  11. version: v1
  12. template:
  13. metadata:
  14. labels:
  15. app: dubbo-samples-mesh-consumer
  16. version: v1
  17. annotations:
  18. sidecar.istio.io/rewriteAppHTTPProbers: "false"
  19. spec:
  20. containers:
  21. - name: server
  22. image: hub.guazi-cloud.com/lichun4/dubbo-demo2:v1
  23. imagePullPolicy: Always
  24. ports:
  25. - name: grpc-tri
  26. containerPort: 50052
  27. protocol: TCP
  28. - name: http-health
  29. containerPort: 22222
  30. protocol: TCP
  31. env:
  32. - name: POD_NAMESPACE
  33. valueFrom:
  34. fieldRef:
  35. fieldPath: metadata.namespace
  36. livenessProbe:
  37. ......
  38. readinessProbe:
  39. ......
  40. startupProbe:
  41. ......

 pod中的两个容器分别如下:其中 server容器为业务容器

4.部署生产者V2(provider-v2)

provider-v2-deployment

  1. apiVersion: apps/v1
  2. kind: Deployment
  3. metadata:
  4. name: dubbo-samples-mesh-provider-v2
  5. namespace: dubbo-demo
  6. spec:
  7. replicas: 2
  8. selector:
  9. matchLabels:
  10. app: dubbo-samples-mesh-provider
  11. version: v2
  12. template:
  13. metadata:
  14. labels:
  15. app: dubbo-samples-mesh-provider
  16. version: v2
  17. annotations:
  18. sidecar.istio.io/rewriteAppHTTPProbers: "false"
  19. spec:
  20. containers:
  21. - name: server
  22. image: apache/dubbo-demo:dubbo-samples-mesh-provider-v2_0.0.1
  23. imagePullPolicy: Always
  24. ports:
  25. - name: grpc-tri
  26. containerPort: 50052
  27. protocol: TCP
  28. - name: http-health
  29. containerPort: 22222
  30. protocol: TCP
  31. livenessProbe:
  32. ......
  33. readinessProbe:
  34. ......
  35. startupProbe:
  36. ......

 5.部署DR、VS

DR:

  1. apiVersion: networking.istio.io/v1alpha3
  2. kind: DestinationRule
  3. metadata:
  4. name: dubbo-samples-mesh-provider
  5. namespace: dubbo-demo
  6. spec:
  7. host: dubbo-samples-mesh-provider.dubbo-demo.svc.cluster.local
  8. trafficPolicy:
  9. loadBalancer:
  10. simple: ROUND_ROBIN
  11. subsets:
  12. - name: v1
  13. labels:
  14. version: v1
  15. - name: v2
  16. labels:
  17. version: v2

 VS:

  1. apiVersion: networking.istio.io/v1alpha3
  2. kind: VirtualService
  3. metadata:
  4. name: dubbo-samples-mesh-provider
  5. namespace: dubbo-demo
  6. spec:
  7. hosts:
  8. - dubbo-samples-mesh-provider.dubbo-demo.svc.cluster.local
  9. http:
  10. - route:
  11. - destination:
  12. host: dubbo-samples-mesh-provider.dubbo-demo.svc.cluster.local
  13. subset: v1
  14. port:
  15. number: 50052
  16. weight: 100
  17. - destination:
  18. host: dubbo-samples-mesh-provider.dubbo-demo.svc.cluster.local
  19. subset: v2
  20. port:
  21. number: 50052
  22. 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方式:

  1. <dubbo:reference id="demoService" check="true"
  2. interface="org.apache.dubbo.samples.basic.api.DemoService"
  3. provider-port="20885"
  4. provided-by="istio-dubbo-producer"
  5. provider-namespace="istio-demo"/>

 注:参考文章进行实验:Dubbo proxy mesh using Envoy & Istio | Apache Dubbo

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Monodyee/article/detail/169500
推荐阅读
相关标签
  

闽ICP备14008679号