Container Service for Kubernetes (ACK) is integrated with Log Service. When you create an ACK cluster, you can enable Log Service to collect log data from containers, including standard output (stdout) and text files.
Step 1: Install Logtail
When you create a cluster, select Enable Log service to install Logtail. You can also install Logtail for an existing cluster.
Install Logtail when you create a cluster:
Install Logtail for an existing cluster
- Log on to the ACK console.
- In the left-side navigation pane of the ACK console, click Clusters.
- On the Clusters page, find the cluster that you want to manage and click the name of the cluster or click Details in the Actions column. The details page of the cluster appears.
- In the left-side navigation pane of the details page, choose Logs and Monitoring section, find logtail-ds. . In the
- Click Install next to logtail-ds.
- In the Install message, click OK.
If an earlier version of Logtail is installed, click Upgrade next to logtail-ds.
Step 2: Configure Log Service when you create an application
You can configure Log Service to collect log data from containers when you create an application. You can use the wizard in the console or YAML templates to create applications.
Use the wizard in the console to create an application and configure Log Service
Create an application by using a YAML template
Step 3: Configure advanced settings in the env field
Variable | Description | Example | Considerations |
---|---|---|---|
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 variable specifies a project in Log Service. By default, the project that you specified when you created the cluster is used. |
|
The project must be deployed in the same region as Logtail. |
aliyun_logs_{key}_logstore | Optional. This variable specifies a Logstore in Log Service. By default, the Logstore is named {key}. |
|
- |
aliyun_logs_{key}_shard | Optional. This variable specifies the number of shards in the Logstore. Valid values: 1 to 10. Default value: 2. |
|
- |
aliyun_logs_{key}_ttl | Optional. This variable specifies the number of days for which log data is retained.
Valid values: 1 to 3650.
|
|
- |
aliyun_logs_{key}_machinegroup | Optional. This variable specifies the node group in which the application is deployed. The default node group is the one in which Logtail is deployed. |
|
- |
- Scenario 1: Collect log data from multiple applications and store them in the same
Logstore
In this scenario, set the aliyun_logs_{key}_logstore variable. The following example shows how to collect stdout from two applications and store the output in stdout-logstore.
The
{key}
of Application 1 is set toapp1-stdout
. The{key}
of Application 2 is set toapp2-stdout
.Configure 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
Configure 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 log data 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 the machine group in the environment variables
for each application. The name of the machine group is the same as that of the machine
group that you created in the previous step.
In the following example, the
{key}
of Application 1 is set toapp1-stdout
. The{key}
of Application 2 is set toapp2-stdout
. If the two applications are deployed in the same ACK cluster, you can use the same machine group for the applications.Configure the following environment variables for Application 1:######### 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
Configure the following environment variables for Application 2:######### Specify environment variables for Application 2########### - name: aliyun_logs_app2-stdout value: stdout - name: aliyun_logs_app2-stdout_project value: app2-project - name: aliyun_logs_app2-stdout_logstore value: app2-logstore - name: aliyun_logs_app2-stdout_machinegroup value: app1-machine-group
- Create a machine group in each project and set the machine group ID in the following
format:
Step 4: View log data
The following example shows how to view the log data of a Tomcat application created by using the wizard in the console. The Log data of the Tomcat application is stored in Log Service. You can log on to the Log Service console to view log data collected from the containers. To view the log data, perform the following steps:
After Log Service is enabled for the application, you can view the logs of containers in the ACK console. Perform the following steps:
- Log on to the ACK console.
- In the left-side navigation pane of the ACK console, click Clusters.
- On the Clusters page, find the cluster that you want to manage and click the name of the cluster or click Details in the Actions column. The details page of the cluster appears.
- In the left-side navigation pane of the details page, choose .
- On the Log Center page, click the Application Logs tab and specify the filter conditions. Then, click Select Logstore to view the logs of containers.
What to do next
- By default, Log Service collects log data by line and does not parse the log data. If you want to change the log collection mode and parse the log data, modify the log collection configurations in the Log Service console. For more information, see the following topics:
- You can also use CustomResourceDefinition (CRD) objects to collect log data from Kubernetes clusters..
- For more information about troubleshooting, see What do I do if errors occur when I use Logtail to collect logs?.