Log Collection

KubeSphere supports multiple log collection methods so that Ops teams can collect, manage, and analyze logs in a unified and flexible way.

This tutorial demonstrates how to collect logs for an example app.

Prerequisites

Enable Log Collection

  1. Log in to the web console of KubeSphere as project-admin and go to your project.

  2. From the left navigation bar, click Log Collection in Project Settings, and then click Log Collection - 图1 to enable the feature.

Create a Deployment

  1. From the left navigation bar, select Workloads in Application Workloads. Under the Deployments tab, click Create.

  2. In the dialog that appears, set a name for the Deployment (for example, demo-deployment) and click Next.

  3. Under Containers, click Add Container.

  4. Enter alpine in the search bar to use the image (tag: latest) as an example.

  5. Scroll down to Start Command and select the checkbox. Enter the following values for Command and Parameters respectively, click , and then click Next.

    Command

    1. /bin/sh

    Parameters

    1. -c,if [ ! -d /data/log ];then mkdir -p /data/log;fi; while true; do date >> /data/log/app-test.log; sleep 30;done

    Note

    The command and parameters above mean that the date information will be exported to app-test.log in /data/log every 30 seconds.

  6. On the Volume Settings tab, click Log Collection - 图2 to enable Collect Logs on Volumes and click Mount Volume.

  7. On the Temporary Volume tab, enter a name for the volume (for example, demo-disk-log-collection) and set the access mode and path.

    Click , and then click Next.

  8. Click Create in Advanced Settings to finish the process.

    Note

    For more information, see Deployments.

View Logs

  1. Under the Deployments tab, click the Deployment just created to go to its detail page.

  2. In Resource Status, you can click Log Collection - 图3 to view container details, and then click Log Collection - 图4 of logsidecar-container (filebeat container) to view logs.

  3. Alternatively, you can also click Log Collection - 图5 in the lower-right corner and select Log Search to view stdout logs. For example, use the Pod name of the Deployment for a fuzzy query.