Create a Event in Kubernetes Using client-go

A Kubernetes event is an object that shows what’s happening inside a cluster, node, pod, or container.

We can publish Kubernetes Events using client-go. It is very easy.

Create an EventRecorder

eventBroadcaster := record.NewBroadcaster()eventBroadcaster.StartLogging(klog.Infof)eventBroadcaster.StartRecordingToSink(&typedcorev1.EventSinkImpl{Interface: clientset.CoreV1().Events("")})eventRecorder := eventBroadcaster.NewRecorder(scheme.Scheme, v1.EventSource{Component: "By Able"})

Send an Event

object := &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: "default"}}eventRecorder.Event(object, v1.EventTypeNormal, "ReasonTest", "MessageTest")

A simple Demo code

A simple Demo code

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Able Lv

Able Lv

252 Followers

Cloud Infrastructure Engineer @Airwallex: Kubernetes, DevOps, Terraform, Istio, Go, and Cloud-Native stuff