Deploy Dubbo3 service to k8s and connect to Istio’s traffic management system (Sidecar mode)

Dubbo version: Dubbo3

lab environment:

k8s version: 1.17.6

istio version: 1.7.3

1. Preparation of resource objects

1. Create an independent namespace and enable sidecar automatic injection

apiVersion: v1
kind:Namespace
metadata:
  name: dubbo-demo
  labels:
    istio-injection: enable #Open sidecar automatic injection

2. Deploy the producer V1 (provider-v1)

Producer 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

Producer 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:
           ?…

The two containers in the pod are as follows: The server container is a business container

3. Deploy the consumer

Deploy 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

consumer 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:
              ?…

The two containers in the pod are as follows: The server container is a business container

4. Deploy the producer 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. Deploy 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

2. Cross flow experiment

Current VS weight ratio provider-v1:provider-v2 = 100:0

View consumer business container logs

kc logs -f dubbo-samples-mesh-consumer-7778c46d5b-kztl5 -n dubbo-demo -c server

It can be observed that the consumer only consumes the data produced by the producer V1, as expected

Adjust the VS weight ratio provider-v1:provider-v2 = 50:50

View consumer business container logs

It can be observed that consumers consume both the data of producer V1 and the data of producer V2, the ratio is about 1:1, which is in line with expectations

Note: In the example, the producer and the consumer belong to the same namespace; if you need to call a different namespace provider, you need to configure it as follows (dubbo version>=3.1.2):

Annotation method:

@DubboReference(providedBy = "istio-demo-dubbo-producer", providerPort = 20885, providerNamespace = "istio-demo")

xml way:

<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"/>

Note: Refer to the article for experiments: Dubbo proxy mesh using Envoy & amp; Istio | Apache Dubbo