This document uses the sample Tomcat application logs as an example. The log output path is /usr/local/tomcat/logs/catalina. *.log.

Step 1. Create a Log Service project

For more information, see the Manage a project.

Step 2. Create a Logstore

For more information, see the Manage a Logstore .

Step 3. Create a machine group

For more information, see the Create a machine group.

Note
We recommend that the machine group ID be set to user-defined ID. User-defined ID is configured to yaml environment variable ALIYUN_LOGTAIL_USER_DEFINED_ID.

Step 4. Create a Logtail configuration

/ecilogs is the mountPath path to the ilogtail container in yaml.


Step 5. Create a Tomcat application

Configure the corresponding environment variable (ENV) based on the following template example and create the pod.

apiVersion: apps/v1beta2
kind: Deployment
metadata:
  name: tomcat-app
  labels:
    k8s-app: tomcat-app
spec:
  selector:
    matchLabels:
      k8s-app: tomcat-app
  template:
    metadata:
      labels:
        k8s-app: tomcat-app
    spec:
      containers:
      - name: ilogtail
        image: registry.cn-hangzhou.aliyuncs.com/acs/ilogtail:0.13.4-eb42407
        env:
          - name: "ALIYUN_REGION_ID"
            value: "${your_region_id}"
          - name: "ALIYUN_LOGTAIL_USER_ID"
            value: "${your_aliyun_user_id}"
          - name: "ALIYUN_LOGTAIL_USER_DEFINED_ID"
            value: "${your_machine_group_name}"
        volumeMounts:
        - name: tomcat-log
          # The root path here will be set to the logtail configuration
          mountPath: /ecilogs
          readOnly: true
      - name: tomcat
        image: tomcat:7.0
        volumeMounts:
        - name: tomcat-log
          # Set application log output path 
          mountPath: /usr/local/tomcat/logs
      volumes:
      - name: tomcat-log
        emptyDir: {}

Description of environment variables:

  • ALIYUN_REGION_ID: Region where the Kubernetes cluster resides. We recommend that the Log Service project resides in the same region as the Kubernetes cluster.
  • ALIYUN_LOGTAIL_USER_ID: Alibaba Cloud Account ID.
  • ALIYUN_LOGTAIL_USER_DEFINED_ID: User ID of the machine group defined by the user in the project.

Step 6. View the Tomcat logs in Log Service