CCE allows you to configure policies for collecting, managing, and analyzing workload logs periodically to prevent logs from being over-sized.
CCE works with AOM to collect workload logs. When a node is created, the ICAgent (the DaemonSet named icagent in the kube-system namespace of the cluster) of AOM is installed by default. After the ICAgent collects workload logs and reports them to AOM, you can view workload logs on the CCE or AOM console.
The ICAgent only collects *.log, *.trace, and *.out text log files.
Parameter |
Description |
---|---|
Storage Type |
|
Add Container Path |
|
*Host Path |
Enter the host path, for example, /var/paas/sys/log/nginx. |
Container Path |
Container path (for example, /tmp) to which the storage resources will be mounted.
NOTICE:
|
Extended Host Path |
This parameter is mandatory only if Storage Type is set to 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.
|
Log Dumping |
Log dump refers to rolling log files on a local host.
NOTE:
|
Multi-line Log |
Some program logs (for example, Java program logs) contain a log that occupies multiple lines. By default, the log collection system collects logs by line. If you want to display logs as a single log message in the log collection system, you can enable the multi-line log function and use the log time or regular pattern mode. When a line of log message matches the preset time format or regular expression, it is considered as the start of a log message and the next line starts with this line of log message is considered as the end identifier of the log message. Split Mode
|
You can set the container log storage path by defining a YAML file.
As shown in the following figure, EmptyDir is mounted a temporary path to /var/log/nginx. In this way, the ICAgent collects logs in /var/log/nginx. The policy field is customized by 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 the HostPath mode. Compared with the EmptyDir mode, the type of volume 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: format: '' volumes: - hostPath: path: /tmp/log name: vol-log imagePullSecrets: - name: default-secret
Parameter |
Explanation |
Description |
---|---|---|
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 dumping |
Log dump refers to rolling log files on a local host.
NOTE:
|
policy.logs.annotations.format |
Multi-line log matching |
Some program logs (for example, Java program logs) contain a log that occupies multiple lines. By default, the log collection system collects logs by line. If you want to display logs as a single log message in the log collection system, you can enable the multi-line log function and use the log time or regular pattern mode. When a line of log message matches the preset time format or regular expression, it is considered as the start of a log message and the next line starts with this line of log message is considered as the end identifier of the log message. The format is as follows: { "multi": { "mode": "time", "value": "YYYY-MM-DD hh:mm:ss" } } multi indicates the multi-line mode.
|
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 standard output of a container.
# View logs of a specified pod. kubectl logs <pod_name> kubectl logs -f <pod_name> # Similar to tail -f # View logs of a specified container in a specified pod. kubectl logs <pod_name> -c <container_name> kubectl logs pod_name -c container_name -n namespace (one-off query) kubectl logs -f <pod_name> -n namespace (real-time query in tail -f mode)