TLS supports collecting container text logs from Kubernetes clusters via DaemonSet. This topic shows how to create collection configurations in the console.
Background information
After installing the LogCollector plugin provided by TLS and creating a collection configuration in the container, LogCollector identifies containers to be collected based on the container’s labels and environment variables. It continuously collects text logs generated in the specified container path and uploads container-related metadata, such as text logs and container names, to the server. LogCollector also supports breakpoint resumes. The checkpoint file retains location information relevant to collection. Therefore, even if LogCollector is stopped and then restarted, it continues collecting from the last saved location.
In a Kubernetes cluster, resources are isolated among pods. As a result, the LogCollector container can not directly access files from containers in other pods. However, the file system of Kubernetes cluster containers is usually built by mounting the host filesystem. This means you can access the container’s rootfs directly from the host. Therefore, after mounting the file system where root directory is located to LogCollector container, LogCollector can access relevant directories on the host to collect files from the business container file system. For example, if a log file is located at /var/log/app.log in a business container, assuming the path mapped to the host machine is /var/lib/kubelet/pods/<pod-id>/xxx/var/log/app.log, LogCollector mounts the host system root directory to its /logcollector_host directory by default. Thus, the actual file path collected by LogCollector is /logcollector_host/var/lib/kubelet/pods/<pod-id>/xxx/var/log/app.log.
In addition, when collecting container text logs, LogCollector supports various collection configurations, such as single-line and multi-line. Aside from the reserved fields that are added by default in various configurations, TLS also adds the following reserved fields to logs collected from containers by LogCollector and automatically creates indexes for these fields.
Limits
- When collecting container standard output:
- Docker container engine only supports JSON type log drivers.
- If a container matches multiple collection configurations, only the latest configuration takes effect on that container.
- When collecting log files inside containers:
- Currently, log file collection paths inside containers support only three methods: No mount, emptyDir mount, and hostPath mount.
- LogCollector does not support setting the collection path to a symbolic link, as LogCollector cannot access symbolic links to log files inside containers. Therefore, configure the collection path using the actual path of the log files in the container.
- After the container stops, LogCollector receives the stop event for that container and immediately stops collecting its logs. If delay exists when LogCollector collects logs from the container, some logs generated before the container stops may not be collected.
- LogCollector supports container engines including Docker and Containerd. Restrictions for accessing different types of container engines are as follows:
- Docker: LogCollector accesses the Docker container engine on the host via /run/docker.sock. Ensure that this path exists and LogCollector has access permissions.
- Containerd: LogCollector accesses the Containerd container engine on the host via /run/containerd/containerd.sock. Ensure that this path exists and LogCollector has access permissions.
Create LogCollector collection configuration
- A host group is created and the host running the containers is added to the group.
- We recommend that you use host group with host identification. The host identification can be set as the custom label you configured during LogCollector installation. That is to say, the identification must match the value of ${your_labels} in the ConfigMap, for example, nginx-log.
Notice
If you are collecting standard container logs from Volcano Engine Container Service VKE, ensure the container service's corresponding cluster network is functioning properly. After LogCollector is installed in the cluster, by default, it automatically creates a host group of the machine identification type in TLS. This host group is located in the same region and belongs to the same project as the cluster, and is named k8s-vke-Container Service Cluster ID.
Step 1 Select a log space
- Select the region where torch log service is located from the top navigation bar.
- On the left navigation bar, select Common functions > Log Collection.
- Then on the Log Collection page, in the LogCollector tab, click Create collection configuration.
Notice
For the regions below, manually select the log collection mode in the LogCollector tab.
Region: Hong Kong (China), Asia Pacific Southeast (Johor), Asia Pacific Southeast (Jakarta).
- Select project and topic, and then click Next: Select host group.
- The collected log data will be stored in the selected log topic.
Step 2 Select host group
- In the All host groups section, select the specified host group for log collection.
- After confirming the host group in the Selected host group section, click Next Step: Collection rule.
Step 3 Configure collection rule
Configure basic information
- Fill in the basic rule configuration.
- (Optional) Enable General container collection rule.
- The general container collection rule specifies the content to collect based on general container information, and also allows exclusion of specific content from collection.
Tip
If neither General container collection rule nor K8s collection rule is enabled, the collection scope covers all containers. When both rules are configured, their logical relationship is AND. That is to say, to successfully collect, both rules need to be met.
- (Optional) Enable K8s collection rule.
- The K8s collection rule specifies the content to collect using Kubernetes container information, and also allows exclusion of specific content from collection.
Tip
If neither General container collection rule nor K8s collection rule is enabled, the collection scope covers all containers. When both rules are configured, their logical relationship is AND. That is to say, to successfully collect, both rules need to be met.
- Enter the Collection path.
- Collection path refers to the directory and filename of the logs. LogCollector matches directories based on the directory part of the collection path and monitors log files in those directories that meet the rules. You can set up to 10 different collection paths.
You can specify a complete directory and filename for collection path. Besides, collection path supports fuzzy matching via wildcard character.
Notice
- By default, a log file can only be collected into one log topic and match only one collection configuration. If multiple collection configurations collect the same file, the latest configuration rule applies.
- TLS currently supports the following wildcards: asterisk (*), double asterisk (**), and question mark (?). Only one double asterisk (**) can be configured at most.
Common configuration methods and examples for collection paths are as follows.
When collecting container text logs with DaemonSet, you can configure reserved field placeholders in the collection path. The placeholder format is {Reserved Field}, which allows dynamic matching of container metadata that is automatically written by LogCollector. For information on supported reserved fields, see Background information. For detailed instructions, refer to Container log path placeholder. For example, if the reserved field includes __pod_name__, you can configure the collection path as /var/log/basic_log/POD_{__pod_name__}/tlsapi/access.log, where {__pod_name__} is a placeholder that LogCollector will replace with the actual Pod name when collecting logs.
- Set collection configuration effectiveness policy.
- When log files under the same collection path are matched by multiple collection configurations, the following policies can be set:
- Set collection path denylist.
- After configuring the collection path denylist, TLS skips the specified directories and files when collecting logs through LogCollector. After selecting Enable, set the denylist directories and files as prompted on the page.
Notice
- Each collection configuration can set up to 10 denylist collection paths.
- When configuring log paths, if you use wildcards but need to exclude certain directories or files, you need to enter the corresponding full paths or filenames in the denylist to ensure effective filtering. For example, if the collection path is /var/log/project/*.log and you want to exclude all subdirectories under /var/log/project, then the collection path denylist should be set to directory paths, with the configured path /var/log/project/**.
The path types in the collection path denylist support setting as directory path and file path.
- Set the Collection policy.
The collection policy determines whether LogCollector collects incremental logs or complete logs. By default, it collects increment logs.
Notice
If the Increment collection policy is selected, after triggering LogCollector collection, the collection policy can not switch to Full collection policy to collect historical logs of the log.
- The collection mode determines how LogCollector parses log files. Select the mode based on your business scenario and configure the corresponding log parsing rules for the chosen mode. For detailed instructions, refer to collection mode section in the documentation for each mode.
- Acquisition point in time: use the system time of the server where LogCollector runs as the log timestamp.
- Custom time: extract the time embedded in the original log as the log timestamp. The related configuration is as follows:
- Select whether to skip files that have not been updated.
- If enabled, LogCollector skips files whose log file update time falls outside your specified time range when collecting data.
- Set whether to enable upload parsing failure log.
- Enable: After enabling, you must also configure the failure log key name. The key name defaults to LogParseFailed. All logs that fail to parse are uploaded to TLS, using the configured failure log key name field as the key and the original log content as the value.
- Disable: Logs that fail to parse are not uploaded to TLS.
Enable plugin configuration.
When collecting text logs via LogCollector, if business logs can not be parsed by regular collection modes like JSON due to complex structures or inconsistent format, use LogCollector plugin for post-collection processing. For more details, see Plugin overview.
- Enable Advanced settings.
- Select advanced configurations based on your needs. If you have no special requirements, we recommend that you keep the default configuration.
- Confirm the collection configuration and click Next step: Check index configuration.
Step 4 Check index configuration
- Check index configuration.
- Follow the prompts on the page to set or update the index as needed. You can also click Import existing index configuration to import indexes from other log topics.
- If the index for this log topic is already configured, you can decide whether to update the index based on the log fields parsed by the collection rule.
Notice
- You must enable the index to query and analyze the collected log data.
- The updated index settings only apply to new data written afterward. For more instructions and limitations on query and analysis, see Query overview and Analysis Overview.
Next steps
After you create the collection configuration, LogCollector collects logs and saves them to the specified log topic. You can then query and analyze logs in log topic. For details, see Query and analysis workflow.