After you enable tracing for an Alibaba Cloud Service Mesh (ASM) instance, you can export the tracing data to Tracing Analysis or a user-created system that is compatible with Zipkin. This topic describes how to configure an ASM instance to export tracing data to a user-created system.

Prerequisites

  • A user-created system that is compatible with Zipkin is built and listens on Zipkin port 9411. If you use Jaeger, Zipkin collectors must be deployed.
  • The user-created system is deployed in a cluster on the data plane.
  • A Container Service for Kubernetes (ACK) cluster is created and added to an ASM instance. For more information, see Add a cluster to an ASM instance.
  • An ingress gateway is deployed for the ACK cluster that is added to the ASM instance. For more information, see Deploy an ingress gateway service.

Step 1: Enable tracing for an ASM instance

  1. Log on to the ASM console.
  2. In the left-side navigation pane, choose Service Mesh > Mesh Management.
  3. On the Mesh Management page, find the ASM instance that you want to configure. Click the name of the ASM instance or click Manage in the Actions column of the ASM instance.
  4. On the management page of the ASM instance, click Settings in the upper-right corner.
  5. In the Settings Update panel, select Enable Tracing Analysis and then User-created Zipkin.
  6. Click OK.

Step 2: Deploy Zipkin in the ACK cluster on the data plane

  1. Save the following YAML code in the zipkin-server.yaml file:
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: zipkin-server
      namespace: istio-system
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: zipkin-server
          component: zipkin
      template:
       metadata:
        labels:
          app: zipkin-server
          component: zipkin
       spec:
        containers:
         - name: zipkin-server
           image: openzipkin/zipkin
           imagePullPolicy: IfNotPresent
           readinessProbe:
                httpGet:
                  path: /health
                  port: 9411
                initialDelaySeconds: 5
                periodSeconds: 5
    Note If you use a custom YAML file to deploy Zipkin, make sure that Zipkin is deployed in the istio-system namespace.
  2. Run the following command to deploy Zipkin in the ACK cluster on the data plane:
    kubectl --kubeconfig=${DATA_PLANE_KUBECONFIG} apply -f zipkin-server.yaml
    Notice If you use the sample code in this topic, replace ${DATA_PLANE_KUBECONFIG} with the path to the kubeconfig file of the cluster on the data plane. In addition, replace ${ASM_KUBECONFIG} with the path to the kubeconfig file of the ASM instance.
  3. After the preceding deployment is complete, verity that the pod where the Zipkin server is deployed can properly start.

Step 3: Create a service to expose the Zipkin server

Create a service that is named zipkin in the istio-system namespace to receive tracing data from ASM or access a specific application. To expose the Zipkin server to the Internet, use the zipkin-svc-expose-public.yaml file. Otherwise, use the zipkin-svc.yaml file. In this example, the zipkin-svc-expose-public.yaml file is used to expose the Zipkin server to the Internet so that you can view tracing data in a convenient manner.

Notice The name of the created service must be zipkin.
  1. Save the following code in a YAML file:
    • To expose the Zipkin server to the Internet, use the zipkin-svc-expose-public.yaml file with the following content:
      apiVersion: v1
      kind: Service
      metadata:
        labels:
          app: tracing
          component: zipkin
        name: zipkin
        namespace: istio-system
      spec:
        externalTrafficPolicy: Cluster
        ports:
        - name: zipkin
          port: 9411
          protocol: TCP
          targetPort: 9411
        selector:
          app: zipkin-server
          component: zipkin
        type: LoadBalancer
    • If you do not need to expose the Zipkin server to the Internet, use the zipkin-svc.yaml file with the following content:
      apiVersion: v1
      kind: Service
      metadata:
        labels:
          app: tracing
          component: zipkin
        name: zipkin
        namespace: istio-system
      spec:
        externalTrafficPolicy: Cluster
        ports:
        - name: zipkin
          port: 9411
          protocol: TCP
          targetPort: 9411
        selector:
          app: zipkin-server
          component: zipkin
        type: ClusterIP
    Note If you use a custom YAML file to deploy the zipkin service, make sure that this service is deployed in the istio-system namespace.
  2. Deploy the zipkin service in the ACK cluster on the data plane.
    # Deploy the zipkin service to expose the Zipkin server to the internal network.
    kubectl --kubeconfig=${DATA_PLANE_KUBECONFIG} apply -f zipkin-svc.yaml
    # Deploy the zipkin service to expose the Zipkin server to the Internet.
    kubectl --kubeconfig=${DATA_PLANE_KUBECONFIG} apply -f zipkin-svc-expose-public.yaml

Step 4: Deploy the Bookinfo application

  1. Run the following command on the kubectl client to deploy the Bookinfo application to the ACK cluster in the ASM instance:
    kubectl --kubeconfig=${DATA_PLANE_KUBECONFIG} apply -f bookinfo.yaml

    The following code is an example of the bookinfo.yaml file:

    apiVersion: v1
    kind: Service
    metadata:
      name: details
      labels:
        app: details
        service: details
    spec:
      ports:
      - port: 9080
        name: http
      selector:
        app: details
    ---
    apiVersion: v1
    kind: ServiceAccount
    metadata:
      name: bookinfo-details
      labels:
        account: details
    ---
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: details-v1
      labels:
        app: details
        version: v1
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: details
          version: v1
      template:
        metadata:
          labels:
            app: details
            version: v1
        spec:
          serviceAccountName: bookinfo-details
          containers:
          - name: details
            image: docker.io/istio/examples-bookinfo-details-v1:1.16.2
            imagePullPolicy: IfNotPresent
            ports:
            - containerPort: 9080
    ---
    ##################################################################################################
    # Ratings service
    ##################################################################################################
    apiVersion: v1
    kind: Service
    metadata:
      name: ratings
      labels:
        app: ratings
        service: ratings
    spec:
      ports:
      - port: 9080
        name: http
      selector:
        app: ratings
    ---
    apiVersion: v1
    kind: ServiceAccount
    metadata:
      name: bookinfo-ratings
      labels:
        account: ratings
    ---
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: ratings-v1
      labels:
        app: ratings
        version: v1
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: ratings
          version: v1
      template:
        metadata:
          labels:
            app: ratings
            version: v1
        spec:
          serviceAccountName: bookinfo-ratings
          containers:
          - name: ratings
            image: docker.io/istio/examples-bookinfo-ratings-v1:1.16.2
            imagePullPolicy: IfNotPresent
            ports:
            - containerPort: 9080
    ---
    ##################################################################################################
    # Reviews service
    ##################################################################################################
    apiVersion: v1
    kind: Service
    metadata:
      name: reviews
      labels:
        app: reviews
        service: reviews
    spec:
      ports:
      - port: 9080
        name: http
      selector:
        app: reviews
    ---
    apiVersion: v1
    kind: ServiceAccount
    metadata:
      name: bookinfo-reviews
      labels:
        account: reviews
    ---
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: reviews-v1
      labels:
        app: reviews
        version: v1
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: reviews
          version: v1
      template:
        metadata:
          labels:
            app: reviews
            version: v1
        spec:
          serviceAccountName: bookinfo-reviews
          containers:
          - name: reviews
            image: docker.io/istio/examples-bookinfo-reviews-v1:1.16.2
            imagePullPolicy: IfNotPresent
            env:
            - name: LOG_DIR
              value: "/tmp/logs"
            ports:
            - containerPort: 9080
            volumeMounts:
            - name: tmp
              mountPath: /tmp
            - name: wlp-output
              mountPath: /opt/ibm/wlp/output
          volumes:
          - name: wlp-output
            emptyDir: {}
          - name: tmp
            emptyDir: {}
    ---
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: reviews-v2
      labels:
        app: reviews
        version: v2
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: reviews
          version: v2
      template:
        metadata:
          labels:
            app: reviews
            version: v2
        spec:
          serviceAccountName: bookinfo-reviews
          containers:
          - name: reviews
            image: docker.io/istio/examples-bookinfo-reviews-v2:1.16.2
            imagePullPolicy: IfNotPresent
            env:
            - name: LOG_DIR
              value: "/tmp/logs"
            ports:
            - containerPort: 9080
            volumeMounts:
            - name: tmp
              mountPath: /tmp
            - name: wlp-output
              mountPath: /opt/ibm/wlp/output
          volumes:
          - name: wlp-output
            emptyDir: {}
          - name: tmp
            emptyDir: {}
    ---
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: reviews-v3
      labels:
        app: reviews
        version: v3
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: reviews
          version: v3
      template:
        metadata:
          labels:
            app: reviews
            version: v3
        spec:
          serviceAccountName: bookinfo-reviews
          containers:
          - name: reviews
            image: docker.io/istio/examples-bookinfo-reviews-v3:1.16.2
            imagePullPolicy: IfNotPresent
            env:
            - name: LOG_DIR
              value: "/tmp/logs"
            ports:
            - containerPort: 9080
            volumeMounts:
            - name: tmp
              mountPath: /tmp
            - name: wlp-output
              mountPath: /opt/ibm/wlp/output
          volumes:
          - name: wlp-output
            emptyDir: {}
          - name: tmp
            emptyDir: {}
    ---
    ##################################################################################################
    # Productpage services
    ##################################################################################################
    apiVersion: v1
    kind: Service
    metadata:
      name: productpage
      labels:
        app: productpage
        service: productpage
    spec:
      ports:
      - port: 9080
        name: http
      selector:
        app: productpage
    ---
    apiVersion: v1
    kind: ServiceAccount
    metadata:
      name: bookinfo-productpage
      labels:
        account: productpage
    ---
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: productpage-v1
      labels:
        app: productpage
        version: v1
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: productpage
          version: v1
      template:
        metadata:
          labels:
            app: productpage
            version: v1
        spec:
          serviceAccountName: bookinfo-productpage
          containers:
          - name: productpage
            image: docker.io/istio/examples-bookinfo-productpage-v1:1.16.2
            imagePullPolicy: IfNotPresent
            ports:
            - containerPort: 9080
            volumeMounts:
            - name: tmp
              mountPath: /tmp
          volumes:
          - name: tmp
            emptyDir: {}
    ---
  2. Run the following command on the kubectl client to deploy virtual services for Bookinfo:
    kubectl --kubeconfig=${ASM_KUBECONFIG} apply -f virtual-service-all-v1.yaml

    The following code is an example of the virtual-service-all-v1.yaml file:

    apiVersion: networking.istio.io/v1alpha3
    kind: VirtualService
    metadata:
      name: productpage
    spec:
      hosts:
      - productpage
      http:
      - route:
        - destination:
            host: productpage
            subset: v1
    ---
    apiVersion: networking.istio.io/v1alpha3
    kind: VirtualService
    metadata:
      name: reviews
    spec:
      hosts:
      - reviews
      http:
      - route:
        - destination:
            host: reviews
            subset: v1
    ---
    apiVersion: networking.istio.io/v1alpha3
    kind: VirtualService
    metadata:
      name: ratings
    spec:
      hosts:
      - ratings
      http:
      - route:
        - destination:
            host: ratings
            subset: v1
    ---
    apiVersion: networking.istio.io/v1alpha3
    kind: VirtualService
    metadata:
      name: details
    spec:
      hosts:
      - details
      http:
      - route:
        - destination:
            host: details
            subset: v1
    ---
  3. Run the following command on the kubectl client to deploy destination rules for Bookinfo:
    kubectl --kubeconfig=${ASM_KUBECONFIG} apply -f destination-rule-all.yaml

    The following code is an example of the destination-rule-all.yaml file:

    apiVersion: networking.istio.io/v1alpha3
    kind: DestinationRule
    metadata:
      name: productpage
    spec:
      host: productpage
      subsets:
      - name: v1
        labels:
          version: v1
    ---
    apiVersion: networking.istio.io/v1alpha3
    kind: DestinationRule
    metadata:
      name: reviews
    spec:
      host: reviews
      subsets:
      - name: v1
        labels:
          version: v1
      - name: v2
        labels:
          version: v2
      - name: v3
        labels:
          version: v3
    ---
    apiVersion: networking.istio.io/v1alpha3
    kind: DestinationRule
    metadata:
      name: ratings
    spec:
      host: ratings
      subsets:
      - name: v1
        labels:
          version: v1
      - name: v2
        labels:
          version: v2
      - name: v2-mysql
        labels:
          version: v2-mysql
      - name: v2-mysql-vm
        labels:
          version: v2-mysql-vm
    ---
    apiVersion: networking.istio.io/v1alpha3
    kind: DestinationRule
    metadata:
      name: details
    spec:
      host: details
      subsets:
      - name: v1
        labels:
          version: v1
      - name: v2
        labels:
          version: v2
    ---
  4. Run the following command on the kubectl client to deploy a gateway for Bookinfo:
    kubectl --kubeconfig=${ASM_KUBECONFIG} apply -f bookinfo-gateway.yaml

    The following code is an example of the bookinfo-gateway.yaml file:

    apiVersion: networking.istio.io/v1alpha3
    kind: Gateway
    metadata:
      name: bookinfo-gateway
    spec:
      selector:
        istio: ingressgateway # use istio default controller
      servers:
      - port:
          number: 80
          name: http
          protocol: HTTP
        hosts:
        - "*"
    ---
    apiVersion: networking.istio.io/v1alpha3
    kind: VirtualService
    metadata:
      name: bookinfo
    spec:
      hosts:
      - "*"
      gateways:
      - bookinfo-gateway
      http:
      - match:
        - uri:
            exact: /productpage
        - uri:
            prefix: /static
        - uri:
            exact: /login
        - uri:
            exact: /logout
        - uri:
            prefix: /api/v1/products
        route:
        - destination:
            host: productpage
            port:
              number: 9080

Step 5: Produce tracing data

  1. Run the following command to query the ingress gateway address of Bookinfo:
    kubectl --kubeconfig=${DATA_PLANE_KUBECONFIG} get svc -n istio-system|grep ingressgateway|awk -F ' ' '{print $4}' 
  2. Enter the ingress gateway address in the address bar of your browser to access Bookinfo in the following format: Ingress gateway address/productpage.

Step 6: View tracing data

  1. Run the following command to obtain the ingress gateway address of the zipkin service:
    kubectl --kubeconfig=${DATA_PLANE_KUBECONFIG} get svc -n istio-system|grep zipkin|awk -F ' ' '{print $4}'
  2. Enter ingress gateway address of the zipkin service:9411 in the address bar of your browser to access the Zipkin console, where you can find tracing data.