微服务之 Dubbo2 sidecar 与 Dubbo3 proxyless通信

Dubbo2 sidecar 与 Dubbo3 proxyless通信

Posted by 董江 on Tuesday, August 22, 2023

Dubbo2 sidecar 与 Dubbo3 proxyless通信

Dubbo 2 绝大部分使用dubbo 协议 + 自定义序列化. 默认 hessian2; 2.7版本以后开始支持grpc协议 Dubbo 3 支持triple 协议, 兼容grpc协议

实现互通

实现 dubbo2 + envoydubbo3 proxyless 模式, 服务注册与发现,限流和截流方式

部署方式

依赖安装部署

  1. Kind 部署:
dongjiang@MacBook Pro: $ go install sigs.k8s.io/kind@v0.20.0 && kind create cluster
go: downloading sigs.k8s.io/kind v0.20.0
go: downloading github.com/alessio/shellescape v1.4.1
go: downloading golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c
go: downloading github.com/pelletier/go-toml v1.9.4
go: downloading github.com/BurntSushi/toml v1.0.0
go: downloading github.com/google/safetext v0.0.0-20220905092116-b49f7bc46da2
dongjiang@MacBook Pro: $ kubectl get node                                          
NAME                 STATUS   ROLES           AGE   VERSION
kind-control-plane   Ready    control-plane   88d   v1.25.3
  1. 部署安装istio,istio/baseistio/istiod:
dongjiang@MacBook Pro:k8s $ helm repo add istio https://istio-release.storage.googleapis.com/charts
dongjiang@MacBook Pro:k8s $ helm repo update
Hang tight while we grab the latest from your chart repositories...
...Successfully got an update from the "gatekeeper" chart repository
...Successfully got an update from the "kubeservice-stack" chart repository
...Successfully got an update from the "sigstore" chart repository
...Successfully got an update from the "koderover-chart" chart repository
...Successfully got an update from the "bitnami" chart repository
...Successfully got an update from the "istio" chart repository
Update Complete. ⎈Happy Helming!⎈

dongjiang@MacBook Pro:k8s $ kubectl create namespace istio-system
dongjiang@MacBook Pro:k8s $ helm install istio-base istio/base -n istio-system
dongjiang@MacBook Pro:k8s $ helm install istiod istio/istiod -n istio-system --set values.global.jwtPolicy=first-party-jwt --wait

dongjiang@MacBook Pro:k8s $ kubectl get deployments -n istio-system -o wide
NAME     READY   UP-TO-DATE   AVAILABLE   AGE     CONTAINERS   IMAGES                         SELECTOR
istiod   1/1     1            1           4h54m   discovery    docker.io/istio/pilot:1.18.2   istio=pilot

dubbo部署安装

先提供providor两个版本,实现两个版本负载

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:
        # Prevent istio rewrite http probe
        sidecar.istio.io/rewriteAppHTTPProbers: "false"
    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
---
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:
        # Prevent istio rewrite http probe
        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         
---
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
---
apiVersion: networking.istio.io/v1alpha3
kind: EnvoyFilter
metadata:
  name: cluster
  namespace: dubbo-demo
spec:
  workloadSelector:
    labels:
      app: dubbo-samples-mesh-consumer
  configPatches:
    - applyTo: CLUSTER
      match:
        cluster:
          name: outbound|50052||dubbo-samples-mesh-provider.dubbo-demo.svc.cluster.local
      patch:
        operation: MERGE
        value:
          health_checks:
            - timeout: 5s
              interval: 5s
              initial_jitter: 1s
              interval_jitter: 1s
              interval_jitter_percent: 50
              unhealthy_threshold: 1
              healthy_threshold: 20
              reuse_connection: true
              no_traffic_interval: 2s
              no_traffic_healthy_interval: 4s
              unhealthy_interval: 5s
              unhealthy_edge_interval: 10s
              healthy_edge_interval: 10s
              tls_options:
                alpn_protocols:
                  - http1.1
                  - h2
              transport_socket_match_criteria:
                useMTLS: true
              grpc_health_check:
                authority: dubbo-samples-mesh-provider.dubbo-demo.svc.cluster.local
---
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:
              # Specifies the port on the host being addressed. If the service exposes only one port, you don't need to choose the port explicitly
              number: 50052
          weight: 80
        - destination:
            host: dubbo-samples-mesh-provider.dubbo-demo.svc.cluster.local
            subset: v2
            port:
              # Specifies the port on the host being addressed. If the service exposes only one port, you don't need to choose the port explicitly
              number: 50052
          weight: 20

---
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:
      # Envoy load balancing strategy
      simple: ROUND_ROBIN
  subsets:
    - name: v1
      labels:
        version: v1
    - name: v2
      labels:
        version: v2
  1. 部署consumor proxyless
apiVersion: apps/v1
kind: Deployment
metadata:
  name: dubbo-samples-xds-consumer
  namespace: dubbo-demo
spec:
  replicas: 2
  selector:
    matchLabels:
      app: dubbo-samples-xds-consumer
  template:
    metadata:
      labels:
        app: dubbo-samples-xds-consumer
    spec:
      containers:
        - name: server
          image: apache/dubbo-demo:dubbo-samples-xds-consumer_0.0.1
---
apiVersion: v1
kind: Service
metadata:
  name: dubbo-samples-xds-consumer
  namespace: dubbo-demo
spec:
  clusterIP: None
  selector:
    app: dubbo-samples-xds-consumer
  ports:
    - name: grpc
      protocol: TCP
      port: 50051
      targetPort: 50051

在其配置dubbo-consumer.properties中,配置后段发现地址

dubbo.application.name=dubbo-samples-xds-consumer
dubbo.application.metadataServicePort=20885
dubbo.application.metadataServiceProtocol=dubbo
dubbo.registry.address=xds://istiod.istio-system.svc:15012
dubbo.consumer.timeout=3000
dubbo.consumer.check=false
dubbo.application.qosEnable=true
dubbo.application.qosAcceptForeignIp=true

代码中发现provider服务

@Component("annotatedConsumer")
public class GreetingServiceConsumer {

    @DubboReference(version = "1.0.0", providedBy = "dubbo-samples-mesh-provider")
    private GreetingService greetingService;

    public String doSayHello(String name) {
        return greetingService.sayHello(name);
    }

}

实现

istiod中各种服务注册和发现情况:

dongjiang@MacBook Pro:~ $ kubectl logs istiod-59cfc8df56-qv7dx -n istio-system
...
2023-08-22T08:31:13.079136Z     info    ads     RDS: PUSH request for node:dubbo-samples-mesh-provider-7c558db5bf-69cg2 resources:7 size:4.6kB cached:6/7
2023-08-22T08:31:13.158498Z     info    ads     LDS: PUSH request for node:dubbo-samples-mesh-provider-7c558db5bf-69cg2 resources:14 size:30.1kB
2023-08-22T08:31:13.378605Z     info    ads     RDS: PUSH request for node:dubbo-samples-mesh-provider-7c558db5bf-5wtpw resources:7 size:4.6kB cached:6/7
2023-08-22T08:31:13.622381Z     info    ads     RDS: PUSH request for node:dubbo-samples-mesh-provider-7c558db5bf-rkbc8 resources:7 size:4.6kB cached:6/7
2023-08-22T08:31:13.648578Z     info    ads     LDS: PUSH request for node:dubbo-samples-mesh-provider-7c558db5bf-5wtpw resources:14 size:30.1kB
2023-08-22T08:31:14.098484Z     info    ads     LDS: PUSH request for node:dubbo-samples-mesh-provider-7c558db5bf-rkbc8 resources:14 size:30.1kB
2023-08-22T08:31:15.637475Z     info    ads     EDS: PUSH request for node:dubbo-samples-xds-consumer-8586c4974c-npwg7 resources:1 size:627B empty:0 cached:1/1
2023-08-22T08:31:16.421437Z     info    ads     EDS: PUSH request for node:dubbo-samples-xds-consumer-8586c4974c-f2pft resources:1 size:627B empty:0 cached:1/1
2023-08-22T08:31:16.527851Z     info    ads     RDS: PUSH request for node:dubbo-samples-mesh-provider-7c558db5bf-wc7vn resources:7 size:4.6kB cached:6/7
2023-08-22T08:31:16.550734Z     info    ads     LDS: PUSH request for node:dubbo-samples-mesh-provider-7c558db5bf-wc7vn resources:14 size:30.1kB
...

consumer中请求providor情况

dongjiang@MacBook Pro:~ $ kubectl logs dubbo-samples-xds-consumer-8586c4974c-f2pft -n dubbo-demo
···
[22/08/23 08:37:22:022 UTC] grpc-default-executor-2  INFO protocol.AbstractProtocol:  [DUBBO] receive notification from xds server, type: type.googleapis.com/envoy.config.route.v3.RouteConfiguration requestId: 2, dubbo version: 1.0-SNAPSHOT, current host: 10.244.0.11
result: hello, xDS Consumer! from host: 10.244.0.7
[22/08/23 08:37:22:022 UTC] grpc-default-executor-3  INFO protocol.AbstractProtocol:  [DUBBO] receive notification from xds server, type: type.googleapis.com/envoy.config.listener.v3.Listener requestId: 4, dubbo version: 1.0-SNAPSHOT, current host: 10.244.0.11
result: hello, xDS Consumer! from host: 10.244.0.7
result: hello, xDS Consumer! from host: 10.244.0.4
result: hello, xDS Consumer! from host: 10.244.0.18
result: hello, xDS Consumer! from host: 10.244.0.4
result: hello, xDS Consumer! from host: 10.244.0.7
result: hello, xDS Consumer! from host: 10.244.0.4
result: hello, xDS Consumer! from host: 10.244.0.4
···

结论

  1. 控制面注册发现等xds 是grpc; 数据面 支持 httpgrpc 协议流量拦截
  2. 支持dubbo2与dubbo3通信,应该只能使用istiod作为注册中心,做服务发现(本质和其他注册中心区别不大)
  3. 一个是dubbo3 + sidecar 和一个dubbo3开启xds framework注册, 两者也可以通信的;

a. values.global.jwtPolicy=first-party-jwt 模式; b. Kubernetes version >= 1.20+

「如果这篇文章对你有用,请随意打赏」

Kubeservice博客

如果这篇文章对你有用,请随意打赏

使用微信扫描二维码完成支付