Alibaba Cloud provides the Tracing Analysis service that offers developers of distributed applications various features, such as trace mapping, request statistics, and trace topology. The Tracing Analysis service helps you quickly analyze and diagnose performance bottlenecks in a distributed application architecture and improves the efficiency of development and diagnostics for microservices applications. You can install the Application Load Balancer (ALB) Ingress controller and enable the Xtrace feature in a cluster. After the Xtrace feature is enabled, you can view the tracing data.
Prerequisites
The ALB Ingress controller is installed in the cluster, and the version of the component is 2.11.1 or later.
When you create a cluster, select ALB Ingress on the right side of the Ingress field on the Component Configurations page. For more information, see Create an ACK managed cluster, Create an ACK dedicated cluster, or Create an ACK Serverless cluster.
For more information about how to install and update the ALB Ingress controller for an existing cluster, see Manage components.
If you want to use an ALB Ingress to access Services deployed in an ACK dedicated cluster, you need to first authorize the cluster to access the ALB Ingress controller. For more information, see Authorize an ACK dedicated cluster to access the ALB Ingress controller.
A kubectl client is connected to the Container Service for Kubernetes (ACK) cluster. For more information, see Obtain the kubeconfig file of a cluster and use kubectl to connect to the cluster.
Managed Service for OpenTelemetry is
activated.
Enable Tracing Analysis for an AlbConfig
Step 1: Enable Logtail for the cluster
After you enable Simple Log Service, the cluster automatically creates a Simple Log Service project. For more information, see Step 1: Install Logtail.
Step 2: Obtain the ID of the Simple Log Service project for subsequent operations
Log on to the ACK console. In the left-side navigation pane, click Clusters.
On the Clusters page, click the name of the cluster that you want to manage and click Cluster Information in the left-side navigation pane.
On the Cluster Information page, click the Cluster Resources tab and copy the ID next to the Log Service Project parameter.
Step 3: Create an AlbConfig
Use an AlbConfig to create an ALB instance and listeners. Enable Simple Log Service for the ALB instance to collect access logs. Configure the parameters related to the Xtrace feature in the AlbConfig. Enable the Xtrace feature to set the sampling algorithm and sampling rate.
Copy the following content to the alb-test.yaml file. The file is used to create an AlbConfig.
apiVersion: alibabacloud.com/v1 kind: AlbConfig metadata: name: alb-demo spec: config: name: alb-test addressType: Intranet zoneMappings: # The specified vSwitch must be in a zone supported by the ALB instance and in the same virtual private cloud (VPC) as the cluster. To ensure the high availability of services, select at least two vSwitches in different zones. -vSwitchId: vsw-2vc82nndnoo********** # Specify the IDs of the vSwitches that are used by the ALB instance. - vSwitchId: vsw-2vc30f5mlhs********** accessLogConfig: logProject: "k8s-log-xz92lvykqj1siwvif****" # Specify the ID of the Simple Log Service project that you obtained. logStore: The name of the alb_xz92lvykqj1siwvif****# The Logstore name must start with alb_. If the specified Logstore does not exist, the system automatically creates one. listeners: - port: 80 protocol: HTTP logConfig: accessLogRecordCustomizedHeadersEnabled: false accessLogTracingConfig: # The parameters related to the Xtrace feature. tracingEnabled: true # Specify whether to enable or disable the Xtrace feature. The default value is false. To enable Xtrace, set this parameter to true. tracingSample: 9999 # The sampling rate of the Xtrace feature. Valid values: 1 to 10000. This parameter takes effect only if you set tracingEnabled to true. tracingType: Zipkin # The sampling algorithm of the Xtrace feature. Set the value to Zipkin. This parameter takes effect only if you set tracingEnabled to true.
NoteFor more information about how to create a vSwitch, see Create and manage a vSwitch.
You can modify the Xtrace configurations only if you enable the access log feature of Simple Log Service for the ALB instance.
Run the following command to create an AlbConfig:
kubectl apply -f alb-test.yaml
Expected output:
albconfig.alibabacloud.com/alb-demo created
Step 4: Create an IngressClass
Create a file named alb.yaml and copy the following content to the file. The file is used to create an IngressClass.
apiVersion: networking.k8s.io/v1 kind: IngressClass metadata: name: alb spec: controller: ingress.k8s.alibabacloud/alb parameters: apiGroup: alibabacloud.com kind: AlbConfig name: alb-demo
Run the following command to create an IngressClass:
kubectl apply -f alb.yaml
Expected output:
ingressclass.networking.k8s.io/alb created
Step 5: Create a Service and configure forwarding rules for the Ingress
Create a file named cafe-service.yaml and copy the following content to the file. The file is used to create a Deployment named coffee and a Service named coffee.
apiVersion: apps/v1 kind: Deployment metadata: name: coffee spec: replicas: 2 selector: matchLabels: app: coffee template: metadata: labels: app: coffee spec: containers: - name: coffee image: registry.cn-hangzhou.aliyuncs.com/acs-sample/nginxdemos:latest ports: - containerPort: 80 --- apiVersion: v1 kind: Service metadata: name: coffee-svc spec: ports: - port: 80 targetPort: 80 protocol: TCP selector: app: coffee type: NodePort
Run the following command to deploy the Deployment and Service:
kubectl apply -f cafe-service.yaml
Expected output:
deployment.apps/coffee created service/coffee-svc created
Create a file named cafe-ingress.yaml and copy the following content to the file. The file is used to configure forwarding rules for the ALB Ingress to expose the Service.
apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: cafe-ingress spec: ingressClassName: alb rules: - host: demo.domain.ingress.top http: paths: # Specify a context path. - path: /coffee pathType: ImplementationSpecific backend: service: name: coffee-svc port: number: 80
Run the following command to configure the publicly-accessible domain name and path of the coffee Service:
kubectl apply -f cafe-ingress.yaml
Expected output:
ingress.networking.k8s.io/cafe-ingress created
Step 6: Configure domain name resolution
If you set the spec.rules.host
parameter to a custom domain name when you create the Ingress, you must add a CNAME record to map the domain name to the domain name of the ALB instance. Then, you can access the Service through the custom domain name. For more information, see (Optional) Step 5: Configure domain name resolution.
Step 7: Access the Service
When you access the Service, the generated request contains an Xtrace ID.
Run the following command to obtain the address of the ALB instance (ADDRESS):
kubectl get ing
Expected output:
NAME CLASS HOSTS ADDRESS PORTS AGE cafe-ingress alb demo.domain.ingress.top alb-u53i28ewt580*****.cn-<Region>.alb.aliyuncs.com 80 16m
Run the following command to access the Service:
curl -H Host:demo.domain.ingress.top http://alb-u53i28ewt580*****.cn-<Region>.alb.aliyuncs.com/coffee
The expected output is an HTML page with the title
Hello World
.
Verify Tracing Analysis
Check requests sent to the ALB instance in Simple Log Service to confirm that the Xtrace data is marked.
Log on to the ACK console. In the left-side navigation pane, click Clusters.
On the Clusters page, click the name of the cluster that you want to manage and click Cluster Information in the left-side navigation pane.
On the Cluster Information page, click the Cluster Resources tab, and then click the link next to Log Service Project to go to the Simple Log Service console. In the left-side navigation pane, click the Logstore whose name starts with
alb_
, such as alb_xz92lvykqj1siwvif**** in this example. Then, search forxtrace
on the current page.
Log on to the Managed Service for OpenTelemetry console.
On the Applications page, select a region in the top navigation bar and click the name of the application that you want to manage.
In the left-side navigation pane, click Interface Calls, and then click the Traces tab to view the tracing data.
On the Traces tab, you can view up to 100 traces with the longest duration for the application. For more information about the tracing data, see API calls.
References
For more information about how to enable Tracing Analysis for NGINX Ingresses, see Enable Tracing Analysis for NGINX Ingresses.
If you encounter errors when you use ALB, see ALB Ingress controller troubleshooting and ALB Ingress FAQ.