Updated on 2025-08-12 GMT+08:00

Reporting Logs to LTS

Scenario

Log Tank Service (LTS) analyzes and processes massive amounts of log data to maximize the availability and performance of cloud services and applications. CCI 2.0 reports logs of containers in each pod to LTS.

  1. Log in to the LTS console and create a log group.

  2. Create a log stream in the created log group.

  3. Log in to the CCI 2.0 console. In the navigation pane, choose Workloads. On the Deployments tab, click Create from YAML.

  4. Edit the YAML file.

    apiVersion: cci/v2
    kind: Deployment
    metadata:
      name: test
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: test
      template:
        metadata:
          annotations:
            logconf.k8s.io/fluent-bit-log-type: lts      # Where logs are reported
            logconfigs.logging.openvessel.io: "{\"default-config\":{\"container_files\":{\"container-0\":\"stdout.log;/root/out.log;/data/emptydir-volume/*.log\"},\"regulation\":\"/(?<log>\\\\d+-\\\\d+-\\\\d+ \\\\d+:\\\\d+:\\\\d+.*)/\",\"lts-log-info\":{\"349b50f7-f6ba-4768-86f9-e7f84ab677c0\":\"8a9e0589-c3b5-4ed1-b8cd-1e8a54612d0e\"}}}"  # Log reporting configuration
          labels:
            app: test
        spec:
          containers:
          - image: centos:latest
            command: ['sh', '-c', "while true; do echo hello; touch /root/out.log; echo hello >> /root/out.log; touch /data/emptydir-volume/emptydir.log; echo hello >> /data/emptydir-volume/emptydir.log; sleep 10; done"]     # Command used to simulate log writing
            volumeMounts:
            - name: emptydir-volume
              mountPath: /data/emptydir-volume
            - name: emptydir-memory-volume
              mountPath: /data/emptydir-memory-volume
            name: container-0
            resources:
              limits:
                cpu: 100m
                memory: 100Mi
              requests:
                cpu: 100m
                memory: 100Mi
          volumes:
          - name: emptydir-volume
            emptyDir: {}
          - name: emptydir-memory-volume
            emptyDir:
              sizeLimit: 1Gi
              medium: Memory
      strategy:
        type: RollingUpdate
        rollingUpdate:
          maxSurge: 1
          maxUnavailable: 0

    In annotations, logconfigs.logging.openvessel.io specifies configuration items for log reporting, and the configuration items are in JSON format. The following describes each configuration item:

    {
        "default-config": { // Configuration name. You can change it as needed.
            "container_files": { // You can set the log collection paths of multiple containers. stdout.log indicates standard output. /root/out.log indicates the text logs in rootfs (volumes included). /data/emptydir-xxx/*.log indicates the directories in rootfs (volumes included).
                "container-0": "stdout.log;/root/out.log;/data/emptydir-volume/*.log",
                ...
            },
            "regulation": "/(?<log>\\d+-\\d+-\\d+ \\d+:\\d+:\\d+.*)/",  // Regular expression matching rule for collecting multi-line logs
            "lts-log-info": { // Only one log group and one log stream are allowed.
                "f938a11a-678e-4631-80a0-3667be1280f7": "a248c18b-61ed-4de2-8f7f-c042b78bb0fd" // Log group ID and log stream ID in the format of {log-group-ID}:{log-stream-ID}
            }
        },
        "other-config": { // Other settings
            ...
        }
    }

  5. Wait until the workload enters the running state and click View Log in the Operation column to view the logs reported by the pod.