Container Compute Service (ACS) integrates with Simple Log Service (SLS) to collect container logs — both stdout and text file logs. This guide shows how to enable log collection in an ACS cluster by deploying an AliyunLogConfig custom resource, defined using a CustomResourceDefinition (CRD).
Prerequisites
Before you begin, ensure that you have an ACS cluster.
Step 1: Install the alibaba-log-controller add-on
When creating an ACS cluster, select the Enable Log Service check box to install alibaba-log-controller automatically. If you skipped this step, install the add-on after cluster creation:
-
Log on to the ACS console. In the left-side navigation pane, click Clusters.
-
On the Clusters page, click the ID of the target cluster. In the left-side navigation pane of the cluster details page, choose Operations > Add-ons.
-
In the Logs and Monitoring section, find alibaba-log-controller and click Install. In the Install alibaba-log-controller dialog box, click OK.
If an earlier version of alibaba-log-controller is already installed, note your current custom settings and environment variables before updating — they will be overwritten when the component is updated. After the update completes, reconfigure your custom settings and environment variables.
Step 2: Create an AliyunLogConfig CRD to configure log collection
In the left-side navigation pane of the cluster details page, choose Custom Resources > CRDs > Create from YAML to create an AliyunLogConfig.
Parameters
| Parameter | Required | Description | Example |
|---|---|---|---|
.metadata.name |
Required | Name of the AliyunLogConfig. Must be unique within the ACS cluster. | test-stdout |
.spec.project |
Optional | Name of the SLS project. Use the format k8s-log-<ACS cluster ID>. |
k8s-log-c326bc86**** |
.spec.logstore |
Required | Name of the Logstore. SLS creates it automatically if it does not exist. | test-stdout |
.spec.logtailConfig.inputType |
Required | Log source type. file for text logs; plugin for stdout. |
plugin |
.spec.logtailConfig.configName |
Required | Name of the Logtail configuration. Must match .metadata.name. |
test-stdout |
.spec.logtailConfig.inputDetail |
Required | Logtail configuration details, including how to collect stdout or text logs. | See YAML examples below. |
.spec.logtailConfig.inputDetail.advanced |
Optional | Extended Kubernetes filter settings. Filters pods by namespace, pod name, container name, or label. | See YAML examples below. |
The advanced field supports the following Kubernetes filters:
-
K8sNamespaceRegex: Filter pods by namespace (supports regular expressions). -
K8sContainerRegex: Filter containers by container name (supports regular expressions). -
K8sPodRegex: Filter pods by pod name (supports regular expressions). -
IncludeK8sLabel: Filter pods by label.
For a full list of Logtail parameters, see Logtail configurations.
Choose a collection method
Pick the scenario that matches how your application writes logs:
-
Scenario 1 — your application writes to stdout or stderr (the default for most containerized workloads).
-
Scenario 2 — your application writes logs to files inside the container (for example,
/log/*.log).
Scenario 1: Collect stdout from specific applications
To scope collection to specific pods or containers, add Kubernetes filter conditions to the detail field inside logtailConfig. After deploying the AliyunLogConfig, SLS collects stdout and stderr only from pods that match the filters.
apiVersion: log.alibabacloud.com/v1alpha1
kind: AliyunLogConfig
metadata:
name: test-stdout
spec:
project: k8s-log-c326bc86**** # Replace with the actual project name.
logstore: test-stdout
shardCount: 2
lifeCycle: 90
logtailConfig:
inputType: plugin
configName: test-stdout
inputDetail:
plugin:
inputs:
- type: service_docker_stdout
detail:
Stdout: true
Stderr: true
K8sNamespaceRegex: ^(default)$
K8sContainerRegex: ^(busybox)$
K8sPodRegex: ^backend.+$
IncludeK8sLabel:
app: backend
application: prod
Scenario 2: Collect text logs from specific applications
To scope collection to specific pods or containers, add Kubernetes filter conditions to the advanced field inside logtailConfig. After deploying the AliyunLogConfig, SLS collects text logs only from pods that match the filters.
apiVersion: log.alibabacloud.com/v1alpha1
kind: AliyunLogConfig
metadata:
name: test-file
spec:
project: k8s-log-c326bc86**** # Replace with the actual project name.
logstore: test-file
logtailConfig:
inputType: file
configName: test-file
inputDetail:
logType: common_reg_log
logPath: /log/
filePattern: "*.log"
dockerFile: true
advanced:
k8s:
K8sNamespaceRegex: ^(default)$
K8sContainerRegex: ^(busybox)$
K8sPodRegex: ^backend.+$
IncludeK8sLabel:
app: backend
application: prod
After creating the AliyunLogConfig, check the SLS console to confirm the corresponding Logstore is created (see Step 4). If a Logstore is missing, review your Logtail configurations and correct any parameter errors.
Step 3: Create a test application
After deploying the AliyunLogConfig, SLS automatically collects logs from newly created pods that match the filter conditions. Deploy the following Deployment to generate test logs — the container continuously prints both stdout and text log output.
apiVersion: apps/v1
kind: Deployment
metadata:
name: backend-busybox
labels:
app: backend
application: prod
spec:
replicas: 1
selector:
matchLabels:
app: backend
application: prod
template:
metadata:
name: backend-busybox
labels:
app: backend
application: prod
spec:
containers:
- args:
- -c
- mkdir -p /log; while true; do echo hello world; date; echo hello sls >> /log/busybox.log; sleep 1; done
command:
- /bin/sh
image: registry-cn-hangzhou.ack.aliyuncs.com/ack-demo/busybox:1.28
imagePullPolicy: Always
name: busybox
Step 4: View logs in the SLS console
After the Deployment is running, verify that logs are flowing into SLS:
-
Log on to the Simple Log Service console.
-
In the Projects section, find the project for your ACS cluster (default name:
k8s-log-{ACS cluster ID}) and click the project name to open the Logstore tab. -
In the Logstores list, click the name of the Logstore specified in your log collection configuration.
On the log query page, confirm the following:
-
The test-stdout Logstore contains log entries with stdout output (for example,
hello worldand the current date). -
The test-file Logstore contains log entries from the file log (for example,
hello sls).
If either Logstore is missing or empty, the AliyunLogConfig may not have been applied correctly. Review the CRD configuration and check the alibaba-log-controller pod logs for errors.

What's next
-
To troubleshoot Logtail log collection errors, see What do I do if errors occur when I use Logtail to collect logs?