Event monitoring

Updated at:
Copy as MD

Event monitoring is a Kubernetes monitoring method that complements resource monitoring by offering improved real-time performance, accuracy, and broader scenario coverage. You can use kube-eventer to send cluster events to external systems such as DingTalk, Log Service (SLS), and EventBridge. It also provides filtering capabilities at different levels to enable real-time event collection, targeted alerting, and asynchronous archiving.

Background

ACK Serverless provides an out-of-the-box event monitoring solution for containerized environments. The kube-eventer component, maintained by the ACK team, provides this capability.

image

kube-eventer is an open source tool maintained by the ACK team for exporting Kubernetes events. It can send cluster events to systems such as DingTalk, SLS, and EventBridge, and provides multi-level filtering for real-time collection, targeted alerting, and asynchronous archiving. For more information, see kube-eventer.

This topic describes event monitoring through the following three use cases:

Prerequisites

The kube-eventer add-on is installed.

Note

On your cluster management page, in the left-side navigation pane, choose Operations > Add-ons. On the Logs and Monitoring tab, install the kube-eventer add-on. The add-on is free but consumes pod resources.

Use case 1: Store Kubernetes events with SLS

Alibaba Cloud Log Service (SLS) allows you to persistently store Kubernetes events for enhanced archiving and auditing. For more information, see Create and use the K8s Event Center.

  1. Create a project and a Logstore.

    1. Log on to the Simple Log Service console.

    2. In the Projects section, click Create Project. Fill in the basic project information and click Create.

      This example creates a project named k8s-log4j in the same region as the Kubernetes cluster, China (Hangzhou).

      Note

      To reduce costs and improve efficiency, we recommend that you create your SLS project in the same region as your Kubernetes cluster. This allows log data to be transmitted over the internal network. This avoids data transfer fees for public network traffic and reduces latency for real-time log collection and querying.

    3. After creation, the k8s-log4j project appears in the project list. Click the project name to open the project details page.

    4. By default, you are on the Logstore page. In the left-side pane, click the plus sign (+) to open the Create Logstore dialog box.

    5. Enter the Logstore configuration information and click OK.

      This example creates a Logstore named k8s-logstore.

      image

    6. After the Logstore is created, a prompt appears to guide you through data import. Click Data Import Wizard to open the Import Data dialog box.

    7. Select Log4j 1/2 and follow the on-screen instructions to configure it.

      This example uses the default settings. You can customize the configuration for your specific log data use case.

      自定义数据

  2. Configure log4j in the Kubernetes cluster.

    1. On the Clusters page, click the name of your cluster. In the left navigation pane, click Applications > Helm.

    2. On the Helm page, find the kube-eventer component. In the Actions column, click Update. Modify the following parameters and click OK.

      • Under npd, set enabled to false.

      • Set eventer.sinks.sls.enabled to true.

      • Set eventer.sinks.sls.logstore to the name of the Logstore that you created in Step 1.

      • Set eventer.sinks.sls.project to the name of the Project that you created in Step 1.

  3. After you perform an operation on the cluster that generates an event, such as deleting a pod or creating an application, log on to the SLS console to view the collected data. For more information, see Consume log data by using an API.

    查看采集数据

  4. Configure indexing and archiving. For more information, see Create an index.

    1. In the SLS console, go to the Projects section and click the name of your project.

    2. Click the 日志库管理图标 icon next to the Logstore name and choose Search & Analysis.

    3. In the upper-right corner, click Enable Index.

    4. In the Search & Analysis dialog box, configure the index and click OK.

      The log query and analysis page appears.日志分析页面

      Note
      • The index configuration takes effect within one minute.

      • After you enable or modify an index, the new configuration applies only to data written after the change.

    5. (Optional) For offline archiving and computing, you can ship data from the Logstore to MaxCompute or OSS. For more information, see Create a MaxCompute shipping task (new) and Create an OSS shipping task (new).

Use case 2: Store Kubernetes events with EventBridge

EventBridge is a serverless event bus service provided by Alibaba Cloud. It allows Alibaba Cloud services, custom applications, and SaaS applications to connect through a standard, centralized hub. You can send ACK events to EventBridge to build loosely coupled, distributed, event-driven architectures. For more information about EventBridge, see What is EventBridge?.

  1. Activate EventBridge. For more information, see Activate EventBridge and grant permissions.

  2. On the Clusters page, click the name of your cluster. In the left navigation pane, click Applications > Helm.

  3. On the Helm page, find the kube-eventer component. In the Actions column, click Update. Set eventer.sinks.eventbridge.enable to true to enable the EventBridge sink, and then click OK.

    eventer:
      accessKeyId: ""
      accessKeySecret: ""
      enabled: true
      env:
        - TZ: Asia/Shanghai
      image:
        pullPolicy: Always
        repository: registry-cn-hangzhou-vpc.ack.aliyuncs.com/acs/kube-eventer
        tag: v1.2.11-0620284-aliyun
      othersinks: null
      resources:
        limits:
          cpu: "1.0"
          memory: 1024Mi
        requests:
          cpu: 100m
          memory: 200Mi
      sinks:
        dingtalk:
          enabled: false
          label: ""
          level: Warning
          monitorkinds: Node,Pod
          monitornamespaces: ""
          token: ""
        eventbridge:
          enabled: false
  4. After the data sink is enabled, view the container events in the EventBridge console.

    1. Log on to the EventBridge console.

    2. In the left-side navigation pane, click Event Buses.

    3. On the Event Buses page, click the name of the target event bus.

    4. In the left-side navigation pane, click Event Trace.

    5. Select an event query method, set the query conditions, and click Search.

    6. In the event list, find the event you want to view and click Event Details in the Actions column.

      For more information, see Query events.

Use case 3: Kubernetes monitoring with a DingTalk chatbot

Monitoring Kubernetes events and sending alerts with a DingTalk chatbot is a typical implementation of ChatOps. Follow these steps:

  1. Configure a DingTalk chatbot.

    1. In a DingTalk group, click the 群设置 icon in the upper-right corner to go to the Group Settings page.

    2. Click Chatbot, then click Add Robot, and select the type of robot to add. For this example, select a Custom robot.

    3. On the Robot details page, click Add to open the Add Robot page.

      Configure the chatbot based on the information below, read and agree to the terms of service, and then click Finish.

      Parameter

      Description

      Edit profile picture

      (Optional) Set a profile picture for the chatbot.

      Chatbot name

      The name of the chatbot to add.

      Add to Group

      The group where the chatbot will be added.

      Security settings

      Three types of security settings are supported: Custom Keywords, Signature, and IP Address (or CIDR block).

      For cluster event monitoring, only the Custom Keywords security setting is currently supported.

      Select Custom Keywords and enter Warning to receive all monitoring alerts. If the chatbot sends messages too frequently, you can add more keywords to filter the alerts. You can set up to 10 keywords. To be delivered, messages sent from ACK Serverless must contain one of these keywords.

    4. Click Copy to copy the webhook URL.

      Note

      On the ChatBot page, select the target chatbot and click the 设置按钮 icon to perform the following operations:

      • Modify the chatbot's profile picture and name.

      • Enabled or Close message notifications.

      • Reset the webhook URL.

      • Delete the chatbot.

  2. Update the configuration of the kube-eventer component.

    1. On the Clusters page, click the name of the target cluster. In the left-side navigation pane, choose Applications > Helm.

    2. On the Helm page, find the kube-eventer component. In the Actions column, click Update. Modify the following parameters and click OK.

      • Under npd, set enabled to false.

      • Set eventer.sinks.dingtalk.enabled to true.

      • In the Token field, enter the access token from the webhook URL that you created in Step 1.

Expected result:

Thirty seconds after a successful deployment, the kube-eventer component takes effect. When an event's severity level exceeds the configured threshold, an alert like the following is sent to the DingTalk group.消息提醒