Collecting Container Logs Using ICAgent (Not Recommended)
CCE works with AOM 1.0 to collect workload logs. When a node is created, ICAgent (a DaemonSet named icagent in the kube-system namespace of a cluster) is installed by default. ICAgent collects workload logs and reports them to AOM 1.0. You can view workload logs on the CCE or AOM 1.0 console.

AOM 1.0 will be taken offline, so you are not advised to use ICAgent to collect container logs and report them to AOM 1.0. Use the Cloud Native Log Collection add-on instead. For details, see Collecting Container Logs Using the Cloud Native Log Collection Add-on.
Constraints
ICAgent only collects text log files in .log, .trace, and .out formats.
Billing
AOM offers a free log collection quota of 500 MB for each account every month. You pay only for the log volume that exceeds the quota. For details, see Billing. You can click here to view logs on the AOM console.
Using ICAgent to Collect Logs
- When creating a workload, choose Logging in Container Information.
- Click
to add a log policy.
- Set Volume Type to hostPath or emptyDir.
Table 1 Parameters for configuring a log policy Parameter
Description
Volume Type
- hostPath: A host path is mounted to the specified container path (mount path). After it is mounted, you can view the container logs that have been saved there.
- emptyDir: A temporary path of the node is mounted to the specified path (mount path). After it is mounted, any logs in the temporary path that are not reported to AOM by the collector will be lost if the pod is deleted.
hostPath
Enter a host path, for example, /var/paas/sys/log/nginx.
Mount Path
Container path (for example, /tmp) that the storage resources will be mounted to.NOTICE:- Do not mount a volume to a system directory such as / or /var/run, or an exception occurs. Mount the volume to an empty directory. If the directory is not empty, ensure that there are no files that affect container startup. If there are such files, they will be replaced, which will lead to a container startup or workload creation failure.
- If the container is mounted to a high-risk directory, use an account with minimum permissions to start the container. Otherwise, high-risk files on the host may be damaged.
- AOM collects only the first 20 logs that have been modified recently. It collects logs from 2 levels of subdirectories by default.
- AOM only collects text log files in .log, .trace, and .out formats in the mount paths.
- For details about how to set permissions for mount points in a container, see Configure a Security Context for a Pod or Container.
Extended Host Path
This parameter is mandatory only if Volume Type is set to hostPath.
Extended host paths contain pod IDs or container names to distinguish different containers into which the host path is mounted.
A level-3 directory is added to the original volume directory/subdirectory. You can easily obtain the files output by a single Pod.
- None: No extended path is configured.
- PodUID: ID of a pod.
- PodName: name of a pod.
- PodUID/ContainerName: ID of a pod or name of a container.
- PodName/ContainerName: name of a pod or container.
Log Dump
Log dump refers to rotating log files on a local host.
- Enable: AOM scans log files every minute. When a log file exceeds 50 MB, it is dumped immediately. A new .zip file is generated in the directory where the log file resides. For a log file, AOM stores only the latest 20 .zip files. When the number of .zip files exceeds 20, earlier .zip files will be deleted.
- Disable: AOM does not dump log files.
NOTE:- AOM rotates log files using copytruncate. Before enabling log dumping, ensure that log files are written in the append mode. Otherwise, file holes may occur.
- Currently, mainstream log components such as Log4j and Logback support log file rotation. If you have already set rotation for log files, skip the configuration. Otherwise, conflicts may occur.
- You are advised to configure log file rotation for your own services to flexibly control the size and number of rolled files.
- Click OK.
Example YAML
You can set the container log storage path by defining a YAML file.
As shown below, an emptyDir volume is mounted to /var/log/nginx. In this way, the ICAgent collects logs in /var/log/nginx. policy is a custom field of CCE and allows the ICAgent to identify and collect logs.
apiVersion: apps/v1 kind: Deployment metadata: name: testlog namespace: default spec: selector: matchLabels: app: testlog template: replicas: 1 metadata: labels: app: testlog spec: containers: - image: 'nginx:alpine' name: container-0 resources: requests: cpu: 250m memory: 512Mi limits: cpu: 250m memory: 512Mi volumeMounts: - name: vol-log mountPath: /var/log/nginx policy: logs: rotate: '' volumes: - emptyDir: {} name: vol-log imagePullSecrets: - name: default-secret
The following shows how to use a hostPath volume. Compared with emptyDir, the type of volumes is changed to hostPath, and the path on the host needs to be configured for this hostPath volume. In the following example, /tmp/log on the host is mounted to /var/log/nginx. In this way, the ICAgent can collects logs in /var/log/nginx, without deleting the logs from /tmp/log.
apiVersion: apps/v1 kind: Deployment metadata: name: testlog namespace: default spec: replicas: 1 selector: matchLabels: app: testlog template: metadata: labels: app: testlog spec: containers: - image: 'nginx:alpine' name: container-0 resources: requests: cpu: 250m memory: 512Mi limits: cpu: 250m memory: 512Mi volumeMounts: - name: vol-log mountPath: /var/log/nginx readOnly: false extendPathMode: PodUID policy: logs: rotate: Hourly annotations: volumes: - hostPath: path: /tmp/log name: vol-log imagePullSecrets: - name: default-secret
Parameter |
Description |
Remarks |
---|---|---|
extendPathMode |
Extended host path |
Extended host paths contain pod IDs or container names to distinguish different containers into which the host path is mounted. A level-3 directory is added to the original volume directory/subdirectory. You can easily obtain the files output by a single Pod.
|
policy.logs.rotate |
Log dump |
Log dump refers to rotating log files on a local host.
NOTE:
|
Viewing Logs
After a log collection path is configured and the workload is created, the ICAgent collects log files from the configured path. The collection takes about 1 minute.
After the log collection is complete, go to the workload details page and click Logs in the upper right corner to view logs.
You can also view logs on the AOM console.
You can also run the kubectl logs command to view the container stdout.
- View the logs of a specified pod.
kubectl logs <pod_name> -n <namespace>
- View the logs of a specified pod in real time.
kubectl logs -f <pod_name> -n <namespace>
- View the logs of a specified container in a specified pod.
kubectl logs <pod_name> -c <container_name> -n <namespace>
- View the logs of a specified container in a specified pod in real time.
kubectl logs -f <pod_name> -c <container_name> -n <namespace>
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.