This document describes how to use eventer to collect events from Kubernetes and send them to Simple Log Service.
The Kubernetes architecture is based on a state machine. Transitions between states generate corresponding events. Transitions between normal states generate Normal-level events, and transitions between normal and abnormal states generate Warning-level events.
Container Service for Kubernetes (ACK) provides an out-of-the-box event monitoring solution for container scenarios. It uses the ACK-maintained NPD and the included kube-eventer to provide container event monitoring.
Node Problem Detector (NPD) is a diagnostic tool for Kubernetes nodes. It converts node anomalies, such as Docker Engine hangs, Linux kernel hangs, network egress issues, or file descriptor anomalies, into node events. When combined with kube-eventer, NPD enables a closed-loop system for node event alerting. For more information, see NPD.
kube-eventer is an open source tool maintained by ACK for the offline processing of Kubernetes events. It pushes cluster events to external systems, such as DingTalk, SLS, and EventBridge. It also provides filter conditions for different event levels to enable real-time collection, targeted alerting, and asynchronous archiving. For more information, see kube-eventer.
Node Problem Detector (NPD) is a diagnostic tool for Kubernetes nodes. It converts node anomalies, such as Docker Engine hangs, Linux kernel hangs, network egress issues, or file descriptor anomalies, into node events. When combined with kube-eventer, NPD enables a closed-loop system for node event alerting. For more information, see NPD.
kube-eventer is an open source tool maintained by ACK for the offline processing of Kubernetes events. It pushes cluster events to external systems, such as DingTalk, SLS, and EventBridge. It also provides filter conditions for different event levels to enable real-time collection, targeted alerting, and asynchronous archiving. For more information, see kube-eventer.
Prerequisites
A Kubernetes cluster is created, such as an Alibaba Cloud ACK cluster or an ACK serverless cluster.
Billing
The K8s event center is free to use under the following conditions.
The retention period for the Logstore associated with the K8s event center is 90 days (the default value).
The daily data volume written to the K8s event center is less than 256 MB (approximately 250,000 events).
For example:
If you do not change the retention period (default is 90 days) and your K8s cluster generates 1,000 events per day, the K8s event center is free.
If you change the retention period to 105 days and your K8s cluster generates 1,000 events per day, you will incur Logstore storage fees for the K8s event center after 90 days. The billable item is Storage - Log Storage. For more information about the Storage - Log Storage billable item, see Pay-as-you-go billable items.
Step 1: Deploy kube-eventer and node-problem-detector
Alibaba Cloud Kubernetes
For an ACK cluster, the ack-node-problem-detector component integrates the features of kube-eventer and node-problem-detector. You only need to deploy this component. For more information, see Event monitoring. For an ACK serverless cluster, you need to deploy the kube-eventer component.
NPD detects node problems or faults based on configurations and third-party plug-ins and then generates corresponding cluster events. The Kubernetes cluster also generates various events due to state transitions, such as pod evictions and image pull failures. The Kubernetes Event Center of Simple Log Service (SLS) aggregates all Kubernetes events in real time and provides storage, query, analysis, visualization, and alerting capabilities. The following steps describe how to send cluster events to the Kubernetes Event Center of SLS:
If you selected Install Node-problem-detector (NPD) and create an Event Center when you created the cluster, proceed to Step 2 to view the Kubernetes Event Center. For more information about how to install the NPD component during cluster creation, see Create an ACK managed cluster.
If you did not select Install Node-problem-detector and Create an Event Center when you created the cluster, you can install it manually.
Log on to the ACK console. In the left navigation pane, click Clusters.
On the Clusters page, click the name of the target cluster. In the left navigation pane, choose .
On the Log and Monitoring tab, find and install ack-node-problem-detector.
Other Kubernetes
Deploy kube-eventer.
Install kubectl. For more information, see Obtain the kubeconfig file of a cluster and use kubectl to connect to the cluster.
Create a configuration file named eventer.yaml using the following sample code.
apiVersion: apps/v1 kind: Deployment metadata: labels: name: kube-eventer name: kube-eventer namespace: kube-system spec: replicas: 1 selector: matchLabels: app: kube-eventer template: metadata: labels: app: kube-eventer annotations: scheduler.alpha.kubernetes.io/critical-pod: '' spec: dnsPolicy: ClusterFirstWithHostNet serviceAccount: kube-eventer containers: - image: registry.cn-hangzhou.aliyuncs.com/acs/kube-eventer:v1.2.5-cc7ec54-aliyun name: kube-eventer command: - "/kube-eventer" - "--source=kubernetes:https://kubernetes.default" ## Send to SLS ## --sink=sls:https://{endpoint}?project={project}&logStore=k8s-event®ionId={region-id}&internal=false&accessKeyId={accessKeyId}&accessKeySecret={accessKeySecret} - --sink=sls:https://cn-beijing.log.aliyuncs.com?project=k8s-xxxx&logStore=k8s-event®ionId=cn-beijing&internal=false&accessKeyId=xxx&accessKeySecret=xxx env: # If TZ is assigned, set the TZ value as the time zone - name: TZ value: "Asia/Shanghai" volumeMounts: - name: localtime mountPath: /etc/localtime readOnly: true - name: zoneinfo mountPath: /usr/share/zoneinfo readOnly: true resources: requests: cpu: 10m memory: 50Mi limits: cpu: 500m memory: 250Mi volumes: - name: localtime hostPath: path: /etc/localtime - name: zoneinfo hostPath: path: /usr/share/zoneinfo --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: name: kube-eventer rules: - apiGroups: - "" resources: - events verbs: - get - list - watch --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: name: kube-eventer roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: kube-eventer subjects: - kind: ServiceAccount name: kube-eventer namespace: kube-system --- apiVersion: v1 kind: ServiceAccount metadata: name: kube-eventer namespace: kube-systemConfiguration
Type
Required
Description
endpoint
string
Required
The endpoint of Simple Log Service. For more information, see Endpoints.
project
string
Required
The project of Simple Log Service.
logStore
string
Required
The Logstore of Simple Log Service.
internal
string
Self-managed Kubernetes cluster: Yes.
For a self-managed Kubernetes cluster, you must set this parameter to false.
regionId
string
Self-managed Kubernetes cluster: Yes.
The ID of the region where Simple Log Service resides. For more information, see Endpoints.
accessKeyId
string
Self-managed Kubernetes cluster: Yes.
The AccessKey ID. Use the AccessKey pair of a RAM user. For more information, see AccessKey pair.
accessKeySecret
string
Self-managed Kubernetes cluster: Yes.
The AccessKey secret. Use the AccessKey pair of a RAM user. For more information, see AccessKey pair.
Run the following command to apply the configurations from eventer.yaml to the cluster.
kubectl apply -f eventer.yamlExpected output:
deployment.apps/kube-eventer created clusterrole.rbac.authorization.k8s.io/kube-eventer created clusterrolebinding.rbac.authorization.k8s.io/kube-eventer created serviceaccount/kube-eventer created
Deploy node-problem-detector.
For more information, see the project on GitHub.
Step 2: Create a K8s event center instance
After you create a K8s event center, Simple Log Service automatically creates a Logstore named k8s-event and associated dashboards in the destination project.
Log on to the Simple Log Service console.
In the Log Application section, on the AIOps tab, click K8s Event Center.
On the Event Hub Management page, click Add in the upper-right corner.
In the Create Event Center panel, configure the parameters, and then click Next.
If you select Existing Project, select a project that you created from the Project drop-down list. This project is used to manage resources for the K8s event center, such as Logstores and dashboards.
If you select Select K8s Cluster from Container Service, select an existing K8s cluster from the K8s Cluster drop-down list. When you use this method, Simple Log Service creates a project named
k8s-log-{cluster-id}by default to manage resources for the K8s event center, such as Logstores and dashboards.
Step 3: Use a K8s event center instance
After you create a K8s event center and deploy kube-eventer and NPD, you can perform operations in the K8s event center. These operations include viewing event overviews, querying event details, viewing pod lifecycles, viewing node events, viewing core component events, setting alerts, running custom queries, and updating versions.
On the K8s Event Center page, find the target K8s event center instance and click the
icon to perform various operations.

Operation | Description |
View event overview | The Event Overview page displays summary statistics for core events, such as the total number of events, a comparison between the numbers of Error events today and yesterday, statistics of alerts, trends of Error events, and details of pod OOM events. Note Pod OOM information cannot be traced to a specific pod. It can only identify the node, process name, and process ID where the event occurred. You can run a custom query to find pod restart events around the time of the OOM occurrence to locate the specific pod. |
Query event details | The Event Details Query page displays event details filtered by various dimensions, such as event type, event target, Host, Namespace, and Name. |
View pod lifecycle | The Pod Lifecycle page displays a graph of events from a pod's entire lifecycle. You can also filter important pod events by event level. |
View node events | The Node Events page displays details about events that occur on a node, such as the Node lifecycle and a list of events. |
View core component events | The Core Component Events page displays details about core component events, such as a failed ECS restart or an unexecuted URL pattern. |
Set alerts | On the Alert Configuration page, you can configure alerts for the K8s event center. For more information, see Configure alerts. |
Custom Query | On the Custom Query page, you can customize query and analysis statements. All events in the K8s event center are stored in a Logstore. You can use all features of the Logstore, such as custom queries, event consumption, custom report creation, and custom alert creation. For more information, see Quick start for query and analysis. If you want to access the project where the K8s event center resides, you can obtain the project name in one of the following two ways.
|
Update version | On the Version Update page, you can upgrade the K8s event center. |
Log sample
The following is a log sample.
hostname: cn-hangzhou.i-***********"
level: Normal
pod_id: 2a360760-****
pod_name: logtail-ds-blkkr
event_id: {
"metadata":{
"name":"logtail-ds-blkkr.157b7cc90de7e192",
"namespace":"kube-system",
"selfLink":"/api/v1/namespaces/kube-system/events/logtail-ds-blkkr.157b7cc90de7e192",
"uid":"2aaf75ab-****",
"resourceVersion":"6129169",
"creationTimestamp":"2019-01-20T07:08:19Z"
},
"involvedObject":{
"kind":"Pod",
"namespace":"kube-system",
"name":"logtail-ds-blkkr",
"uid":"2a360760-****",
"apiVersion":"v1",
"resourceVersion":"6129161",
"fieldPath":"spec.containers{logtail}"
},
"reason":"Started",
"message":"Started container",
"source":{
"component":"kubelet",
"host":"cn-hangzhou.i-***********"
},
"firstTimestamp":"2019-01-20T07:08:19Z",
"lastTimestamp":"2019-01-20T07:08:19Z",
"count":1,
"type":"Normal",
"eventTime":null,
"reportingComponent":"",
"reportingInstance":""
}Log Field | Data Type | Description |
hostname | String | The hostname where the event occurred. |
level | String | The log level. Valid values: Normal and Warning. |
pod_id | String | The unique ID of the pod. This field exists only when the event type is related to a pod. |
pod_name | String | The name of the pod. This field exists only when the event type is related to a pod. |
event_id | JSON | The details of the event. This field is a JSON string. |
FAQ
No data in the K8s event center instance
After you deploy the K8s event center, new events are automatically collected. You can search for these events on the Custom Query page. We recommend that you set the time range in the upper-right corner to 1 day. If no data is found, the cause may be one of the following:
No events were generated in the K8s cluster after the K8s event center was deployed.
You can run the
kubectl get events --all-namespacescommand to check whether new events are generated in the cluster.Incorrect parameters were configured when you deployed kube-eventer and node-problem-detector.
If you use an ACK cluster, perform the following steps:
Log on to the Container Service for Kubernetes (ACK) console.
On the Clusters page, click the name of the destination cluster.
In the navigation pane on the left, choose .
On the Helm page, click Update for ack-node-problem-detector.
Check and modify the parameter settings. For more information, see Step 1: Deploy kube-eventer and node-problem-detector.
If you use a self-managed Kubernetes cluster, see Collect Kubernetes events for information about parameter settings.
How do I view the logs of the container corresponding to an event?
If you use an ACK cluster, perform the following steps:
Log on to the Container Service for Kubernetes (ACK) console.
On the Clusters page, click the name of the target cluster.
In the navigation pane on the left, choose .
Set the Namespace to kube-system.
In the Container Group list, click Log for the target group.
If you use a self-managed Kubernetes cluster, check the logs of the pod that has a name prefixed with eventer-sls in the kube-system namespace.