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. You are advised to disable Send stdout Logs to AOM 1.0 on the Monitoring tab (Monitoring).
ICAgent only collects text log files in .log, .trace, and .out formats.
to add a log policy.The following uses Nginx as an example. Log policies vary depending on workloads.
Parameter | Description |
|---|---|
Volume Type |
|
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:
|
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.
|
Collection Path | A collection path narrows down the scope of collection to specified logs.
Example: The collection path /tmp/**/test*.log indicates that all .log files prefixed with test will be collected from /tmp and subdirectories of five levels deep. CAUTION: Ensure that the version of ICAgent is 5.12.22 or later. |
Log Dump | Log dump refers to rotating log files on a local host.
NOTE:
|
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/v1kind: Deploymentmetadata:name: testlognamespace: defaultspec:selector:matchLabels:app: testlogtemplate:replicas: 1metadata:labels:app: testlogspec:containers:- image: 'nginx:alpine'name: container-0resources:requests:cpu: 250mmemory: 512Milimits:cpu: 250mmemory: 512MivolumeMounts:- name: vol-logmountPath: /var/log/nginxpolicy:logs:rotate: ''volumes:- emptyDir: {}name: vol-logimagePullSecrets:- 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 collect logs in /var/log/nginx, and the logs are still stored in /tmp/log.
apiVersion: apps/v1kind: Deploymentmetadata:name: testlognamespace: defaultspec:replicas: 1selector:matchLabels:app: testlogtemplate:metadata:labels:app: testlogspec:containers:- image: 'nginx:alpine'name: container-0resources:requests:cpu: 250mmemory: 512Milimits:cpu: 250mmemory: 512MivolumeMounts:- name: vol-logmountPath: /var/log/nginxreadOnly: falseextendPathMode: PodUIDpolicy:logs:rotate: Hourlyannotations:pathPattern: '**'volumes:- hostPath:path: /tmp/logname: vol-logimagePullSecrets:- 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:
|
policy.logs.annotations.pathPattern | Collection path | A collection path narrows down the scope of collection to specified logs.
Example: The collection path /tmp/**/test*.log indicates that all .log files prefixed with test will be collected from /tmp and subdirectories of five levels deep. CAUTION: Ensure that the version of ICAgent is 5.12.22 or later. |
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.
kubectl logs <pod_name> -n <namespace>
kubectl logs -f <pod_name> -n <namespace>
kubectl logs <pod_name> -c <container_name> -n <namespace>
kubectl logs -f <pod_name> -c <container_name> -n <namespace>