<p>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 <a href="https://www.bluematador.com/blog/kubernetes-events-explained" rel="noreferrer">Kubernetes events</a> 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 <code>kubectl describe &lt;cr&gt;</code>.</p>

<p>You're looking for an operator. There are already a few pre-written ones out there, check <a href="https://operatorhub.io" rel="nofollow noreferrer">OperatorHub</a>. They are essentially <a href="https://kubernetes.io/docs/concepts/overview/components/#kube-controller-manager" rel="nofollow noreferrer">controllers</a> for custom resources, watching for events and acting on them.</p>

<p>You can also write your own, e.g. with the <a href="https://github.com/operator-framework/operator-sdk" rel="nofollow noreferrer">Operator SDK</a>. 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 <code>kubectl describe</code>.</p>

<p>A good start might be <a href="https://coreos.com/blog/introducing-operators.html" rel="nofollow noreferrer">this post</a> on Operators, and <a href="https://flugel.it/building-custom-kubernetes-operators-part-3-building-operators-in-go-using-operator-sdk/" rel="nofollow noreferrer">this here</a> for listening to events from your custom resources.</p>
