Container Service for Kubernetes (ACK) is deeply integrated with Simple Log Service (SLS). ACK provides log collection components to help you simplify container log collection and management. This topic describes how to install a log collection component and how to configure log collection, such as automated log collection, log query, and log analysis. You can use the preceding configurations to improve O&M efficiency and reduce operating costs.
Scenarios
Log collection components collect logs in the following modes:
DaemonSet mode: suitable for clusters that have clear classifications of logs or have single functions. This mode is introduced in this topic.
Sidecar mode: suitable for large-scale and hybrid clusters. For more information, see Collect text logs from Kubernetes containers in Sidecar mode.
For more information about the differences between the two modes, see Collection method.
Table of contents
Procedure | References |
Step 1: Install a log collection component | Install one of the following log collection components:
|
Step 2: Create a collection configuration | Collect text logs or stdout.
|
Step 3: Query and analyze logs | You can query and analyze logs in the SLS console. |
Step 1: Install a log collection component
Install LoongCollector
Currently, LoongCollector is in canary release. Before you install LoongCollector, check the supported regions.
LoongCollector-based data collection: LoongCollector is a new-generation log collection agent that is provided by Simple Log Service. LoongCollector is an upgraded version of Logtail. LoongCollector is expected to integrate the capabilities of specific collection agents of Application Real-Time Monitoring Service (ARMS), such as Managed Service for Prometheus-based data collection and Extended Berkeley Packet Filter (eBPF) technology-based non-intrusive data collection.
Install the loongcollector component in an existing ACK cluster
Log on to the ACK console. In the left-side navigation pane, click Clusters.
On the Clusters page, click the cluster that you want to manage. In the left-side navigation pane, choose Operations > Add-ons.
On the Logs and Monitoring tab of the Add-ons page, find the loongcollector component and click Install.
NoteYou cannot install the loongcollector component and the logtail-ds component at the same time. If the logtail-ds component is installed in your cluster, you cannot directly upgrade the logtail-ds component to the loongcollector component. The upgrade solution is available soon.
After the LoongCollector components are installed, Simple Log Service automatically generates a project named k8s-log-${your_k8s_cluster_id}
and resources in the project. You can log on to the Simple Log Service console to view the resources. The following table describes the resources.
Resource type | Resource name | Description | Example |
Machine group | k8s-group- | The machine group of loongcollector-ds, which is used in log collection scenarios. | k8s-group-my-cluster-123 |
k8s-group- | The machine group of loongcollector-cluster, which is used in metric collection scenarios. | k8s-group-my-cluster-123-cluster | |
k8s-group- | The machine group of a single instance, which is used to create a LoongCollector configuration for the single instance. | k8s-group-my-cluster-123-singleton | |
Logstore | config-operation-log | The Logstore is used to collect and store loongcollector-operator logs. Important Do not delete the | config-operation-log |
Install Logtail
Logtail-based data collection: Logtail is a log collection agent that is provided by Simple Log Service. You can use Logtail to collect logs from multiple data sources, such as Alibaba Cloud Elastic Compute Service (ECS) instances, servers in data centers, and servers from third-party cloud service providers. Logtail supports non-intrusive log collection based on log files. You do not need to modify your application code, and log collection does not affect the operation of your applications.
Install Logtail components in an existing ACK cluster
Log on to the ACK console. In the left-side navigation pane, click Clusters.
On the Clusters page, find the one you want to manage and click its name. In the left-side navigation pane, choose .
On the Logs and Monitoring tab of the Add-ons page, find the logtail-ds component and click Install.
Install Logtail components when you create an ACK cluster
Log on to the ACK console. In the left-side navigation pane, click Clusters.
On the Clusters page, click Create Kubernetes Cluster. In the Component Configurations step of the wizard, select Enable Log Service.
This topic describes only the settings related to Simple Log Service. For more information about other settings, see Create an ACK managed cluster.
After you select Enable Log Service, the system prompts you to create a Simple Log Service project. You can use one of the following methods to create a project:
Select Project
You can select an existing project to manage the collected container logs.
Create Project
Simple Log Service automatically creates a project to manage the collected container logs.
ClusterID
indicates the unique identifier of the created Kubernetes cluster.
In the Component Configurations step of the wizard, Enable is selected for the Control Plane Component Logs parameter by default. If Enable is selected, the system automatically configures collection settings and collects logs from the control plane components of a cluster, and you are charged for the collected logs based on the pay-as-you-go billing method. You can determine whether to select Enable based on your business requirements. For more information, see Collect logs of control plane components in ACK managed clusters.
After the Logtail components are installed, Simple Log Service automatically generates a project named k8s-log-<YOUR_CLUSTER_ID>
and resources in the project. You can log on to the Simple Log Service console to view the resources. The following table describes the resources.
Resource type | Resource name | Description | Example |
Machine group | k8s-group- | The machine group of logtail-daemonset, which is used in log collection scenarios. | k8s-group-my-cluster-123 |
k8s-group- | The machine group of logtail-statefulset, which is used in metric collection scenarios. | k8s-group-my-cluster-123-statefulset | |
k8s-group- | The machine group of a single instance, which is used to create a Logtail configuration for the single instance. | k8s-group-my-cluster-123-singleton | |
Logstore | config-operation-log | The Logstore is used to store logs of the alibaba-log-controller component. We recommend that you do not create a Logtail configuration for the Logstore. You can delete the Logstore. After the Logstore is deleted, the system no longer collects the operational logs of the alibaba-log-controller component. You are charged for the Logstore in the same manner as you are charged for regular Logstores. For more information, see Billable items of pay-by-ingested-data. | None |
Step 2: Create a collection configuration
Step 3: Query and analyze logs
Log on to the Simple Log Service console.
In the Projects section, click the project that you want to manage to go to the details page of the project.
In the left-side navigation pane, click the
icon of the Logstore that you want to manage. In the drop-down list, select Search & Analysis to view the logs that are collected from your Kubernetes cluster.
Default log fields
Text logs
The following table describes the fields that are included by default in each container text log.
Field name | Description |
__tag__:__hostname__ | The name of the container host. |
__tag__:__path__ | The log file path in the container. |
__tag__:_container_ip_ | The IP address of the container. |
__tag__:_image_name_ | The name of the image that is used by the container. |
__tag__:_pod_name_ | The name of the pod. |
__tag__:_namespace_ | The namespace to which the pod belongs. |
__tag__:_pod_uid_ | The unique identifier (UID) of the pod. |
stdout
The following table describes the fields uploaded by default for each log in a Kubernetes cluster.
Field | Description |
_time_ | The time when the log was collected. |
_source_ | The type of the log source. Valid values: stdout and stderr. |
_image_name_ | The name of the image. |
_container_name_ | The name of the container. |
_pod_name_ | The name of the pod. |
_namespace_ | The namespace of the pod. |
_pod_uid_ | The unique identifier of the pod. |
References
After you collect logs, you can use the query and analysis features in Simple Log Service to obtain information about the collected logs. For more information, see Guide to log query and analysis.
After you collect logs, you can use the visualization feature to collect statistics and view logs in Simple Log Service. For more information, see Create a dashboard.
After you collect logs, you can use the alerting feature to automatically generate alerts for exceptions in logs in Simple Log Service. For more information, see Create an alert rule in Simple Log Service.
Simple Log Service collects only incremental logs. You can also collect historical logs. For more information, see Import historical logs from log files.
You can troubleshoot errors that occur when Simple Log Service collects logs. For more information, see the following topics:
How do I troubleshoot the common errors that may occur when Simple Log Service collects logs?
You can check whether error messages appear in the Simple Log Service console. For more information, see How do I view Logtail collection errors?
If an error occurs when you use Logtail to collect logs but no error messages appear in the Simple Log Service console, you can check the heartbeat status of your machine group and your Logtail configuration. For more information, see What do I do if errors occur when I collect logs from containers?