Define log collection configurations as Kubernetes CRDs for version control, environment-specific deployments, and automated releases with kubectl or CI/CD pipelines across ACK and self-managed clusters. LoongCollector hot-reloads configuration changes without restart.
The legacy AliyunLogConfig CRD is deprecated. Use AliyunPipelineConfig instead. See CRD types for a comparison.CRD-based collection configurations can only be modified by updating the CRD. Changes made in the SLS console are not synchronized and do not take effect.
Applicability
Operating environment
ACK clusters (managed and dedicated editions) and self-managed Kubernetes clusters.
The Kubernetes version must be 1.16.0 or later and support
Mount propagation: HostToContainer.container runtime (Docker and Containerd only)
Docker:
Requires access to docker.sock.
Standard output collection supports only the JSON-file log driver.
Only the overlay and overlay2 storage drivers are supported. For other types of storage drivers, you must manually mount the log directories.
Containerd: Requires access to containerd.sock.
Resource requirements: LoongCollector (Logtail) runs with the 'system-cluster-critical' priority class. Do not deploy if the cluster has insufficient resources — it may evict Pods on nodes.
CPU: Reserve at least 0.1 Core.
Memory: Reserve at least 150 MB for the collection component and at least 100 MB for the controller component.
Actual usage depends on collection rate, monitored directories and files, and send congestion. Keep usage below 80% of configured limits.
Permission requirements: To deploy, the Alibaba Cloud account or RAM user must have the
AliyunLogFullAccesspermission.To create a custom policy, refer to the AliyunCSManagedLogRolePolicy system policy. Copy the permissions from this policy and grant them to the target RAM user or role to configure fine-grained permissions.
Collection configuration workflow
Install LoongCollector: Deploy LoongCollector as a DaemonSet to run a collection container on each cluster node. This configuration centralizes log collection for all containers on the node.
Create a LogStore: A LogStore is a storage unit for log data. Multiple LogStores can be created within a Project.
Create a collection configuration YAML file: Use kubectl to connect to the cluster. You can create the collection configuration file in one of two ways:
Method 1: Use the collection configuration generator
Use the collection configuration generator in the Log Service console to visually configure parameters and automatically generate a standard YAML file.
Method 2: Manually write the YAML file
Manually write a YAML file based on the examples in this document. Build progressively: start with a minimal configuration, add processing logic, then enable advanced features.
For complex scenarios not covered in this document or fields that require deep customization, see AliyunPipelineConfig parameter reference for a complete list of fields, value rules, and plugin capability details.
A complete collection configuration typically includes the following parts:
Minimal configuration (Required): This configuration builds the data pipeline from the cluster to Log Service and consists of two parts:
Inputs (
inputs): Defines the log source. For container logs, sources include the following two types. To collect other types of logs, such as MySQL query results, see Input plugins.Container standard output (stdout and stderr): Logs that the container application prints to the console.
Text log files: Log files written to a specified path inside the container.
Outputs (
flushers): Defines the log destination. Collected logs are sent to the specified LogStore.If the target Project or LogStore does not exist, the system automatically creates it. You can also manually create a Project and a LogStore in advance.
Common processing configurations (Optional): Define the
processorsfield to perform structured parsing (such as regular expression or delimiter parsing), data masking, or filtering on raw logs.This document describes only native processing plugins that cover common log processing scenarios. For more features, see Extended processing plugins.
Other advanced configurations (Optional): Enables advanced features such as multi-line log collection and log tag enrichment to meet more specific collection requirements.
Structure example:
apiVersion: telemetry.alibabacloud.com/v1alpha1 # Use the default value. Do not modify. kind: ClusterAliyunPipelineConfig # Use the default value. Do not modify. metadata: name: test-config # Set the resource name, which must be unique within the current Kubernetes cluster. spec: project: # Set the name of the target Project. name: k8s-your-project config: # Set the Logtail collection configuration. inputs: # Set the input plugins for the Logtail collection configuration. ... processors: # Set the processing plugins for the Logtail collection configuration. ... flushers: # Set the output plugins for the Logtail collection configuration. ...Apply the configuration
kubectl apply -f <your_yaml>
Install LoongCollector (Logtail)
LoongCollector is the next-generation log collection agent from SLS, an upgraded version of Logtail. The two cannot coexist. To install Logtail instead, see Install and configure Logtail.
Follow these steps for basic LoongCollector installation. For detailed parameters, see Installation and configuration. If LoongCollector or Logtail is already installed, skip to logstore creation.
ACK cluster
You can install LoongCollector from the Container Service for Kubernetes (ACK) console. By default, logs are sent to a Simple Log Service Project under the current Alibaba Cloud account.
-
Log on to the ACK console. In the left navigation pane, click Clusters.
On the Clusters page, click the name of the target cluster to open its details page.
In the left-side navigation pane, click Add-ons.
On the Logs and Monitoring tab, find loongcollector, and click Install.
NoteWhen you create a cluster, on the Component Configurations page, select the Enable Log Service checkbox. You can then choose to Create Project or Select Project.
After the installation is complete, Simple Log Service automatically creates related resources in your ACK cluster's region. View these resources in the Simple Log Service console.
Resource type
Resource name
Description
Project
k8s-log-${cluster_id}Isolates logs from different services.
To create a Project for more flexible log resource management, see Create a Project.
machine group
k8s-group-${cluster_id}A group of log collection nodes.
ImportantLoongCollector does not create a logstore named config-operation-log. If a logstore with this name already exists, LoongCollector stops writing logs to it.
Self-managed cluster
Connect to your Kubernetes cluster. Then, run the appropriate command for your region to download LoongCollector and its dependencies:
For regions in the Chinese mainland:
wget https://aliyun-observability-release-cn-shanghai.oss-cn-shanghai.aliyuncs.com/loongcollector/k8s-custom-pkg/3.0.12/loongcollector-custom-k8s-package.tgz; tar xvf loongcollector-custom-k8s-package.tgz; chmod 744 ./loongcollector-custom-k8s-package/k8s-custom-install.shFor regions outside the Chinese mainland:
wget https://aliyun-observability-release-ap-southeast-1.oss-ap-southeast-1.aliyuncs.com/loongcollector/k8s-custom-pkg/3.0.12/loongcollector-custom-k8s-package.tgz; tar xvf loongcollector-custom-k8s-package.tgz; chmod 744 ./loongcollector-custom-k8s-package/k8s-custom-install.shGo to the
loongcollector-custom-k8s-packagedirectory and modify the./loongcollector/values.yamlconfiguration file.# ===================== Required parameters ===================== # The Project where logs are sent. Example: k8s-log-custom-sd89ehdq. projectName: "" # The Project's region. Example: cn-shanghai. region: "" # The UID of the Alibaba Cloud account that owns the Project. Enclose the value in quotation marks. Example: "123456789" aliUid: "" # The network type. Valid values: Internet (public network) and Intranet (internal network). Default: Internet. net: Internet # The AccessKey ID and secret for an Alibaba Cloud account or RAM user that has the AliyunLogFullAccess policy. accessKeyID: "" accessKeySecret: "" # The custom cluster ID. The ID can contain only uppercase letters, lowercase letters, digits, and hyphens (-). clusterID: ""In the
loongcollector-custom-k8s-packagedirectory, run the following command to install LoongCollector and its dependencies:bash k8s-custom-install.sh installAfter the installation is complete, check the status of the components.
If the pods fail to start, verify the values.yaml configuration and ensure the required images were pulled.
# Check pod status kubectl get po -n kube-system | grep loongcollector-dsSimple Log Service also automatically creates the following resources. View these resources in the Simple Log Service console.
Resource type
Resource name
Description
Project
The value of
projectNamethat you specified in the values.yaml fileIsolates logs from different services.
machine group
k8s-group-${cluster_id}A group of log collection nodes.
ImportantLoongCollector does not create a logstore named config-operation-log. If a logstore with this name already exists, LoongCollector stops writing logs to it.
Create a Logstore
If you have already created a logstore, skip this step and go to collection configuration.
Log on to the Log Service console and click the target project.
In the left-side navigation pane, choose
and click +.On the Create Logstore page, configure the following core parameters:
Logstore Name: Enter a name that is unique within the project. This name cannot be changed after creation.
Logstore Type: Choose Standard or Query based on their specifications.
Billing Mode:
Pay-by-feature: You are billed independently for each resource, such as storage, indexing, and read/write operations. Suitable for small-scale use cases or when feature usage is uncertain.
Pay-by-ingested-data: You are billed only for the amount of raw data ingested. This mode provides a 30-day free storage period and free features such as data transformation and delivery. This simple cost model is ideal for cases where the storage period is close to 30 days or the data processing pipeline is complex.
Data Retention Period: Set the number of days to retain logs. The value ranges from 1 to 3650 days. A value of 3650 means permanent storage. The default is 30 days.
Leave the other settings at their defaults and click OK. Manage logstores.
Minimal configuration
In spec.config, you configure input and output plugins to define the log source and destination.
Container standard output
Purpose: Collects container standard output logs (stdout/stderr) that are printed directly to the console.
Defines the log source. Currently, you can configure only one input plugin.
| Example |
Sends collected logs to a specified Logstore in a Project. You can configure up to five output plugins.
|
Container text files
Purpose: Collects logs written to a specific file path inside a container, such as access.log or app.log.
Defines the log source. Currently, you can configure only one input plugin.
| Example |
Sends collected logs to a specified Logstore in a Project. You can configure up to five output plugins.
|
Common configuration
After completing the minimal configuration, add processor plugins to parse, mask, or filter raw logs.
Core configuration: To configure processing plugins, add processors to spec.config, which allows you to enable multiple plugins simultaneously.
This topic covers only native processing plugins that handle common log processing use cases. For more features, see extended processing plugins.
For Logtail 2.0+ and LoongCollector, follow these plugin ordering guidelines:
Prioritize native plugins.
If native plugins do not meet your needs, configure extension plugins to run after them.
Native plugins can only run before extension plugins.
Structured configuration
Regex parsing
Extracts log fields using a regular expression and parses the logs into key-value pairs.
Parameter | Example |
Type Fixed to | |
SourceKey The name of the source field. | |
Regex The regular expression for parsing the log. | |
Keys A list of keys for the extracted fields. | |
KeepingSourceWhenParseFail Whether to retain the source field when parsing fails. Default: | |
KeepingSourceWhenParseSucceed Whether to retain the source field on successful parsing. Default: | |
RenamedSourceKey The new name for the source field if it is kept. If omitted, the source field is not renamed. |
Delimiter parsing
Parses logs into key-value pairs using a single- or multi-character delimiter.
Parameter | Example |
Type Fixed to | |
SourceKey The name of the source field. | |
Separator The field delimiter. For example, CSV files use a comma (,). | |
Keys A list of keys for the extracted fields. | |
Quote The quote character used to wrap fields that contain special characters, such as the delimiter. | |
AllowingShortenedFields Whether to allow fewer extracted fields than Keys. Default: | |
OverflowedFieldsTreatment Behavior when more fields are extracted than Keys. Default:
| |
KeepingSourceWhenParseFail Whether to retain the source field if parsing fails. Default: | |
KeepingSourceWhenParseSucceed Whether to retain the source field on successful parsing. Default: | |
RenamedSourceKey The new name for the source field if it is kept. If omitted, the source field is not renamed. |
Standard JSON parsing
Parses a JSON object from a log field into key-value pairs.
Parameter | Example |
Type Fixed to | |
SourceKey The name of the source field. | |
KeepingSourceWhenParseFail Whether to retain the source field when parsing fails. Default: | |
KeepingSourceWhenParseSucceed Whether to retain the source field on successful parsing. Default: | |
RenamedSourceKey The new name for the source field if it is kept. If omitted, the source field is not renamed. |
Parameter names in the CRD YAML use camelCase, such as RenamedSourceKey. Names in snake_case, such as renamed_source_key, are not valid.
Nested JSON parsing
Flattens a nested JSON object into key-value pairs and allows you to specify the expansion depth.
Parameter | Example |
Type Fixed to | |
SourceKey The name of the source field. | |
ExpandDepth The maximum expansion depth for the nested JSON object. Default: 0.
| |
ExpandConnector The connector used between keys when flattening a nested JSON object. Default: an underscore (_). | |
Prefix The prefix to add to all expanded field names. | |
IgnoreFirstConnector Whether to omit the connector before the top-level field. Default: | |
ExpandArray Whether to expand array types. Default:
Note This parameter is supported in Logtail 1.8.0 and later. | |
KeepSource Whether to retain the original field in the parsed log. Default:
| |
NoKeyError Whether to report an error if the specified source field is not found. Default:
| |
UseSourceKeyAsPrefix If set to true, uses the source field name as a prefix for all expanded field names. | |
KeepSourceIfParseError Whether to retain raw logs when parsing fails. Default:
|
JSON array parsing
Use the json_extract function to extract a JSON object from a JSON array. JSON Functions.
Parameter | Example |
Type The plugin type. The SPL plugin type is | |
Script The SPL script used to extract elements from a JSON array in the content field. | |
TimeoutMilliSeconds The script execution timeout in milliseconds. The value must be between 0 and 10,000. Default value: 1,000. |
NGINX log parsing
Parses NGINX logs into key-value pairs based on your log_format definition. If the default format does not meet your requirements, you can use a custom format.
Parameter | Example |
Type Fixed to | |
SourceKey The name of the source field. | |
Regex The regular expression for parsing the NGINX log. | |
Keys A list of keys for the extracted fields. | |
Extra
| |
KeepingSourceWhenParseFail Whether to keep the original field if parsing fails. Default: | |
KeepingSourceWhenParseSucceed Whether to retain the original field on successful parsing. Default: | |
RenamedSourceKey The new name for the source field if it is kept. If omitted, the source field is not renamed. |
Apache log parsing
Parses Apache logs into key-value pairs based on the format defined in your Apache configuration file.
Parameter | Example |
Type Fixed to | |
SourceKey The name of the source field. | |
Regex The regular expression for parsing the Apache log. | |
Keys A list of keys for the extracted fields. | |
Extra
| |
KeepingSourceWhenParseFail Whether to keep the original field if parsing fails. Default: | |
KeepingSourceWhenParseSucceed Whether to keep the original field on successful parsing. Default: | |
RenamedSourceKey The new name for the source field if it is kept. If omitted, the source field is not renamed. |
Data masking
Use the processor_desensitize_native plugin to mask sensitive data in your logs.
Parameters | Example |
Type Set to | |
SourceKey The name of the source field. | |
Method The masking method. Supported values:
| |
ReplacingString The constant string that replaces sensitive data. This parameter is required when | |
ContentPatternBeforeReplacedString A regular expression for the content that precedes the sensitive data. | |
ReplacedContentPattern A regular expression that matches the sensitive data. | |
ReplacingAll Whether to replace all matches. Default: |
Content filtering
Configure the processor_filter_regex_native plugin to match log field values against a regular expression and retain only matching logs.
Parameters | Example |
Type The plugin type. This value must be | |
FilterRegex A list of regular expressions for matching log field values. | |
FilterKey A list of log field names to apply the FilterRegex patterns to. |
Time parsing
Parse the time field in a log and use the result as the log's __time__ field.
Key fields | Example |
Type The plugin type. Set to | |
SourceKey The source field name. | |
SourceFormat The time format. This must exactly match the time format in the log. | |
SourceTimezone The time zone of the source timestamp. Default: the time zone of the machine running LoongCollector. Format:
|
Advanced configurations
After completing the minimal configuration, use these advanced settings for more granular collection:
Configure multiline log collection: Enable multiline mode with a start-pattern regex to collect entries spanning multiple lines (such as stack traces) as single log records.
Configure log topic types: Assign topics to log streams for easier organization and retrieval.
Specify containers for collection (filtering and blacklisting): Use whitelists and blacklists to collect logs from specific containers and paths only.
Enrich logs with tags: Add metadata from environment variables and pod labels to your logs as tags.
Configure multiline log collection
By default, SLS splits logs line by line, breaking multiline entries like stack traces into separate records.
Enable multiline mode and configure a start-pattern regex to group multiline entries into single log records.
Key configuration: Add the Multiline parameter to the spec.config.inputs configuration.
Field details | Example |
Multiline Enables multiline log collection.
| |
Log topic types
Key configuration: Add the global parameter to spec.config to set the log topic.
Field details | Example |
TopicType The topic type. Valid values:
| Machine group topicFile path extractionCustom |
TopicFormat The topic format. This parameter is required when |
Container filtering and blacklisting
Filtering
Collect logs only from containers matching specified conditions. Multiple conditions combine with logical AND. Empty conditions are ignored. All conditions support regular expressions.
Key configuration: Configure container filtering parameters under ContainerFilters in the spec.config.inputs section.
Field details | Example |
ContainerFilters Container filtering settings.
All regular expression matching is based on the Go language's RE2 engine, which has certain limitations compared to engines like PCRE. Write your regular expressions according to the guidelines in Appendix: Regular expression limits for container filtering. | |
Blacklisting
Exclude files that match specified criteria. To do this, add the following parameters under config.inputs in your YAML configuration as needed:
Field details | Example |
ExcludeFilePaths File path blacklist. Excludes files that match the specified absolute paths. Paths can include the | |
ExcludeFiles File name blacklist. Excludes files with matching names. The names can include the | |
ExcludeDirs Directory blacklist. Excludes directories based on the specified paths. Paths must be absolute and can include the |
Log enrichment with tags
Key configuration: In spec.config.inputs, configure ExternalEnvTag and ExternalK8sLabelTag to map container environment variables and pod labels to log tags.
Field details | Example |
ExternalEnvTag Maps the value of a specified environment variable to a log tag. The format is | |
ExternalK8sLabelTag Maps the value of a Kubernetes pod label to a log tag. The format is |
Configuration examples
Use case 1: Parse Nginx access logs
This configuration parses an Nginx log and structures the content into multiple key-value pairs based on the log_format definition.
Use case 2: Process multiline logs
By default, SLS treats each line as a separate log entry, splitting multiline logs like stack traces into multiple records.
Enable multiline mode with a start-pattern regex to group all lines of a multiline log into a single entry.
FAQ
Managing multi-target distribution
Multi-target distribution configurations are associated with multiple Logstores and must be managed on the project-level management page:
Log on to the Simple Log Service console and click the name of the target project.
On the project page, in the left-side navigation pane, click
.NoteThis page lists all collection configurations in the project, including residual configurations from accidentally deleted Logstores.
Send ACK logs to a cross-account project
Install LoongCollector (Logtail) manually in an ACK cluster and configure it with the target account's credentials to send logs to a project in another Alibaba Cloud account.
Use case: Collect logs from an ACK cluster into a project under a separate account for organizational structure, permission isolation, or unified monitoring.
Procedure: This procedure shows how to manually install LoongCollector. To learn how to install Logtail, see Install and configure Logtail.
Connect to your Kubernetes cluster. Then, run the appropriate command for your region to download LoongCollector and its dependencies:
For regions in the Chinese mainland:
wget https://aliyun-observability-release-cn-shanghai.oss-cn-shanghai.aliyuncs.com/loongcollector/k8s-custom-pkg/3.0.12/loongcollector-custom-k8s-package.tgz; tar xvf loongcollector-custom-k8s-package.tgz; chmod 744 ./loongcollector-custom-k8s-package/k8s-custom-install.shFor regions outside the Chinese mainland:
wget https://aliyun-observability-release-ap-southeast-1.oss-ap-southeast-1.aliyuncs.com/loongcollector/k8s-custom-pkg/3.0.12/loongcollector-custom-k8s-package.tgz; tar xvf loongcollector-custom-k8s-package.tgz; chmod 744 ./loongcollector-custom-k8s-package/k8s-custom-install.shGo to the
loongcollector-custom-k8s-packagedirectory and modify the./loongcollector/values.yamlconfiguration file.# ===================== Required parameters ===================== # The Project where logs are sent. Example: k8s-log-custom-sd89ehdq. projectName: "" # The Project's region. Example: cn-shanghai. region: "" # The UID of the Alibaba Cloud account that owns the Project. Enclose the value in quotation marks. Example: "123456789" aliUid: "" # The network type. Valid values: Internet (public network) and Intranet (internal network). Default: Internet. net: Internet # The AccessKey ID and secret for an Alibaba Cloud account or RAM user that has the AliyunLogFullAccess policy. accessKeyID: "" accessKeySecret: "" # The custom cluster ID. The ID can contain only uppercase letters, lowercase letters, digits, and hyphens (-). clusterID: ""In the
loongcollector-custom-k8s-packagedirectory, run the following command to install LoongCollector and its dependencies:bash k8s-custom-install.sh installAfter the installation is complete, check the status of the components.
If the pods fail to start, verify the values.yaml configuration and ensure the required images were pulled.
# Check pod status kubectl get po -n kube-system | grep loongcollector-dsSimple Log Service also automatically creates the following resources. View these resources in the Simple Log Service console.
Resource type
Resource name
Description
Project
The value of
projectNamethat you specified in the values.yaml fileIsolates logs from different services.
machine group
k8s-group-${cluster_id}A group of log collection nodes.
ImportantLoongCollector does not create a logstore named config-operation-log. If a logstore with this name already exists, LoongCollector stops writing logs to it.
Multiple collections for a single source
By default, SLS restricts each log source to a single collection configuration to prevent duplication:
A text log file can match only one Logtail collection configuration.
A container's standard output (stdout) can match only one standard output collection configuration.
Log on to the Simple Log Service console and go to the target project.
In the left-side navigation pane, select
Logstores and find the target logstore.Click the
icon next to its name to expand the logstore.Click Logtail Configuration. In the configuration list, find the target Logtail configuration and click Manage Logtail Configuration in the Actions column.
On the Logtail Configurations page, click Edit and scroll down to the Input Configurations section:
To collect text file logs, enable Allow File to Be Collected for Multiple Times.
To collect container standard output, enable Allow Collection by Different Logtail Configurations.
Appendix: Regex limits (container filtering)
Regular expressions for container filtering use the Go RE2 engine, which has syntax limitations compared to PCRE:
1. Differences in named group syntax
Go uses the (?P<name>...) syntax for named groups. It does not support the (?<name>...) syntax used in PCRE.
Correct example:
(?P<year>\d{4})Incorrect syntax:
(?<year>\d{4})
2. Unsupported regular expression features
RE2 does not support the following common but complex regular expression features. Avoid using them:
Assertions:
(?=...),(?!...),(?<=...),(?<!...)Conditional expressions:
(?(condition)true|false)Recursive matching:
(?R),(?0)Subprogram references:
(?&name),(?P>name)Atomic groups:
(?>...)
3. Recommendations
When debugging regex with a tool like Regex101, select Golang (RE2) mode. Unsupported syntax prevents the plugin from parsing or matching correctly.