Kubernetes: create events for custom resources

9/14/2019

I have created a custom resource definition (CRD) and a custom resource (CR) in my Kubernetes cluster, but in my CR controller, how do I create Kubernetes events which are attached to my custom resource? I hope with events, users will be able to see important messages associated with the CR when they run kubectl describe <cr>.

-- Dagang
kubernetes
kubernetes-custom-resources

1 Answer

9/16/2019

You're looking for an operator. There are already a few pre-written ones out there, check OperatorHub. They are essentially controllers for custom resources, watching for events and acting on them.

You can also write your own, e.g. with the Operator SDK. When you write your own, you can update the status of the CR, depending on what your operator should do, which then shows up when calling kubectl describe.

A good start might be this post on Operators, and this here for listening to events from your custom resources.

-- char
Source: StackOverflow