TKE Log

Last updated: 2019-11-19 16:48:05

    Overview

    TKE users can directly configure a log collection rule in the console to collect cluster logs and send the collected logs to a specific Cloud Log Service (CLS) log topic. Through the log collection feature, the CLS platform supports real-time search, consumption, and shipping of cluster service logs.

    Access directions

    1. Creating a logset and a log topic

    Log in to the CLS Console and create a logset and a log topic. TKE logs can be collected using independent collector. So, when creating a log topic, you do not need to enable LogListener. For more information, see Creating a Logset and a Log Topic.

    Currently, TKE cluster logs can only be shipped to CLS within the same region.

    2. Associating a TKE cluster

    (1) Log in to the TKE Console. In the left sidebar, click Log Collection. At the top of the log collection page, select region and cluster, and then click Create.
    (2) Create a log collection rule.

    Rule configuration items are described as follows.

    Configuration Item Details
    Collection rule name A name contains up to 63 characters, including lowercase letters, numbers, and separators ("-"), and must begin with a lowercase letter and end with a number or lowercase letter.
    Once set, the name cannot be modified.
    Type 3 types of collection tasks are supported: Collecting container standard output Logs, Collecting container file logs, and Collecting CVM file logs.
    Log source You can choose to collect logs from all containers or a specified container.
    Consumption end Select CLS.
    CLS instance Select logset and log topic.

    TKE supports 3 types of collection tasks. The following describes in detail how to configure these 3 types of collection tasks.

    Collecting container standard output logs

    You can configure shipping standard output logs to CLS from a specified container in the Kubernetes cluster. The shipped logs carry the relevant Kubernetes metadata, including the label and annotation of the pod to which the container belongs.

    (1) On the Create a log collection policy page, select the Container standard output collection type and then configure the log source.

    (2) When you select container standard output as the collection type, the metadata below is added for each log by default, with log as the raw log message. This type of log source supports selecting workloads of multiple Namespaces at the same time.

    Field Name Description
    docker.container_id ID of the container to which logs belong
    kubernetes.annotations Annotations of the pod to which logs belong
    kubernetes.container_name Name of the container to which logs belong
    kubernetes.host IP address of the pod to which logs belong
    kubernetes.labels Labels of the pod to which logs belong
    kubernetes.namespace_name Namespace of the pod to which logs belong
    kubernetes.pod_id ID of the pod to which logs belong
    kubernetes.pod_name Name of the pod to which logs belong
    log Raw log message

    Collecting file logs in container

    You can configure the shipping of logs of files in a specified pod in the cluster to CLS. Logs must be shipped in JSON format, and will carry the relevant Kubernetes metadata, including the label and annotation of the pod to which the container belongs.

    Currently, you can only collect log files stored in volumes. You must mount volumes such as emptyDir and hostpath when creating a workload and save the log files to the specified volume.

    (1) In the Type field, select Container file path, and configure a log source.
    You can specify a file path or use wildcards to collect the log file under the corresponding path on the pod, for example, /var/log/nginx.log or /var/lib/docker/containers/*/*.log.

    (2) When you select the container file path as the collection type, the metadata below is added for each log by default, with message as the raw log message. This type of log source does not support selecting workloads of multiple Namespaces.

    Field Name Description
    docker.container_id ID of the container to which logs belong
    kubernetes.annotations Annotations of the pod to which logs belong
    kubernetes.container_name Name of the container to which logs belong
    kubernetes.host IP address of the pod to which logs belong
    kubernetes.labels Labels of the pod to which logs belong
    kubernetes.namespace_name Namespace of the pod to which logs belong
    kubernetes.pod_id ID of the pod to which logs belong
    kubernetes.pod_name Name of the pod to which logs belong
    file Source log file
    message Raw log message

    Collecting file logs on CVM

    You can configure shipping logs for all nodes in a cluster from the specified CVM path to CLS. The logs are shipped in JSON format with user-specified metadata attached, including the path of the source file and custom metadata.

    (1) On the Create a log collection policy page, select Node file path in the Type field.
    You can specify a file path or use wildcards to collect the log file under the corresponding path on the node in the cluster, for example, /var/log/nginx.log or /var/lib/docker/containers/*/*.log.

    (2) You can add custom metadata as needed. Attach metadata to the collected log messages, specified in key-value format, to serve as metadata tags for the log messages.
    Attached metadata will be added to the log record in JSON format.

    For example:

    • Without specified metadata attached, the collected logs appear as follows:
    • With specified metadata attached, the collected logs appear as follows:

    Compared to logs without specified metadata attached, JSON logs with metadata attached have an additional key service.
    Log metadata is defined as follows:

    Field Name Description
    path Source file of the logs
    message Log message
    Custom key Custom value

    3. Searching TKE logs

    Prerequisites: Before performing the log search, you need to configure and enable the index. For more information, see Enabling Index.

    (1) Log in to the CLS Console. Click Log Search in the left sidebar to enter the search page.
    (2) Select a log topic associated with TKE, and click Search.

    Was this page helpful?

    Was this page helpful?

    • Not at all
    • Not very helpful
    • Somewhat helpful
    • Very helpful
    • Extremely helpful
    Send Feedback
    Help