Alibaba Cloud Container Service for Kubernetes (ACK) is integrated with Log Service. When you create a cluster, you can enable Log Service to collect container logs, including standard output logs (stdout) and text files.
Step 1: Activate Logtail
When you create a cluster, select Enable Log service to activate Logtail. You can also install Logtail for an existing cluster.
Activate Logtail when you create a cluster:
Install Logtail for an existing cluster:

Step 2: Configure Log Service when you create an application
You can configure Log Service to collect container logs when you create an application. You can use the wizard in the console or YAML templates to create applications.
Use the wizard to create an application:
Use a YAML template to create an application
Optional. Step 3: Configure advanced parameters in the env field
Parameter | Description | Example | Notes |
---|---|---|---|
aliyun_logs_{key} |
|
|
|
aliyun_logs_{key}_tags | Optional. This parameter is used to add tags to log data. The value must be in the following format: {tag-key}={tag-value}. |
|
- |
aliyun_logs_{key}_project | Optional. This parameter specifies a project in Log Service. By default, the project that you specified when you create the cluster is used. |
|
The region of the project must be the same as where your Logtail is located. |
aliyun_logs_{key}_logstore | Optional. This parameter specifies a Logstore in Log Service. By default, the Logstore is named after {key}. |
|
- |
aliyun_logs_{key}_shard | Optional. This parameter specifies the number of shards in the Logstore. Valid values: 1 to 10. Default value: 2. |
|
- |
aliyun_logs_{key}_ttl | Optional. This parameter specifies the number of days for which log data is retained.
Valid values: 1 to 3650.
|
|
- |
aliyun_logs_{key}_machinegroup | Optional. This parameter specifies the machine group of the application. The default machine group is the one where your Logtail is located. |
|
- |
- Scenario 1: Collect logs from multiple applications and store them in the same Logstore
In this scenario, set the aliyun_logs_{key}_logstore parameter. The following example shows how to collect standard output logs from two applications and store them in stdout-logstore.
Set the following environment variables for Application 1:######### Specify environment variables ########### - name: aliyun_logs_app1-stdout value: stdout - name: aliyun_logs_app1-stdout_logstore value: stdout-logstore
Set the following environment variables for Application 2:######### Specify environment variables ########### - name: aliyun_logs_app2-stdout value: stdout - name: aliyun_logs_app2-stdout_logstore value: stdout-logstore
- Scenario 2: Collect logs from different applications and store them in different projectsIn this scenario, perform the following steps:
- Create a machine group in each project and set the machine group ID in the following format: k8s-group-{cluster-id}, where {cluster-id} is the ID of the cluster. You can customize the machine group name.
- Specify the project, Logstore, and machine group in the environment variables for
each application.
######### Specify environment variables ########### - name: aliyun_logs_app1-stdout value: stdout - name: aliyun_logs_app1-stdout_project value: app1-project - name: aliyun_logs_app1-stdout_logstore value: app1-logstore - name: aliyun_logs_app1-stdout_machinegroup value: app1-machine-group
Step 4: View logs
The following example shows how to view logs of the Tomcat application created in the console. Tomcat application logs are stored in Log Service. Perform the following steps to view logs:
More information
- By default, Log Service collects logs by line and does not parse the logs. If you want to change the log collection mode and parse the logs, modify the log collection configurations in the Log Service console. For more information, see the following topics:
- You can also use CRDs to collect Kubernetes cluster logs.
- For information about troubleshooting, see Troubleshoot collection errors.