For Python applications deployed on TKE, APM offers automatic connection schemes, enabling automatic agent injection after the application is deployed to TKE, facilitating quick connection.
Automatic connecting Python applications for the TKE environment will use the community OpenTelemetry-Python scheme for agent injection. For more information on OpenTelemetry-Python, see the community OpenTelemetry-Python project. Prerequisites
Step 1: Install Operator.
Step 2: Add annotation to workload.
1. Log in to TKE console. 2. Click Cluster to enter the corresponding TKE cluster.
3. In Workload, locate the application that needs to connect with APM, click More, then click Edit YAML.
4. In the Pod annotation where the application is located, add the following content, then click Complete to finish the connection.
cloud.tencent.com/inject-python: "true"
cloud.tencent.com/otel-service-name: my-app
Note that this content needs to be added to spec.template.metadata.annotations
, affecting the Pod's annotation, not the workload's annotation. You can see the following code snippet:
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
k8s-app: my-app
name: my-app
namespace: default
spec:
selector:
matchLabels:
k8s-app: my-app
template:
metadata:
labels:
k8s-app: my-app
annotations:
cloud.tencent.com/inject-python: "true"
cloud.tencent.com/otel-service-name: my-app
spec:
containers:
image: my-app:0.1
name: my-app
Connection Verification
After an annotation is added to the workload, depending on the published policy, you can trigger the restart of the application Pod. The newly started Pod will automatically inject an agent and connect to the APM server to report monitoring data. The reported business system is the default business system of the Operator. In normal traffic cases, the connected applications will be displayed in APM > Application monitoring > Application list , and the connected application instances will be displayed in APM > Application monitoring > App details > Instance monitoring. Since there is a certain latency in the processing of observable data, if the applications or instances are not found in the console after connecting, wait about 30 seconds. Django Application Precautions
If your application uses the Django framework, pay attention to the following points before connecting:
1. It is recommended to deploy the service using uWSGI. For deployment methods, see through uWSGI Hosting Django Application. Starting directly through the python command may cause reporting failures. 2. The introduction of OpenTelemetry-Python may result in Django applications no longer using the default configuration file. It is necessary to re-specify the configuration file through environment variables:
export DJANGO_SETTINGS_MODULE=mysite.settings
Or add environment variables through a YAML file:
env:
- name: DJANGO_SETTINGS_MODULE
value: mysite.settings
More Connection Configuration Items (Optional)
At the Workload level, you can add more annotations to adjust the connect behaviors:
|
cloud.tencent.com/apm-token | Specify the Token for the APM business system. If this configuration item is not added, the Operator's configuration is used (corresponding to the Operator's env.APM_TOKEN field). |
cloud.tencent.com/python-instr-version | Specify the Python agent version. If this configuration item is not added, the Operator's configuration is used (corresponding to the Operator's
env.PYTHON_INSTR_VERSION field). The value can be latest (default) or a specific version number. For a list of specific version numbers, see Agent Version Information. It is not recommended to fill in this field unless necessary. |
Was this page helpful?