Home Explore Blog CI



kubernetes

4th chunk of `content/en/blog/_posts/2018-01-00-Reporting-Errors-Using-Kubernetes-Events.md`
a0eac80a49e7ffc24be1bfd43b50991db280e48d3572129b00000001000008a4
We experimented with a status web page for the control plane service as an alternative to Kubernetes Events. We determined that the status page could update every time after processing an SSL certificate, and that application owners could probe the status page and get the diagnosis from there. After experimenting with a status page initially, we have seen that this does not work as effectively as the Kubernetes Events solution. The status page becomes a new interface to learn for the application owner, a new web address to remember, and one more context switch to a distinct tool during troubleshooting efforts. On the other hand, Kubernetes Events show up cleanly at the kubectl describe output, which is easily recognized by the developers.  

Here is a simplified example showing how we used Kubernetes Events for error reporting across distinct services. We have open sourced a [sample golang application](https://github.com/box/error-reporting-with-kubernetes-events) representative of the previously mentioned control plane service. It watches changes on CRDs and does input parameter checking. If an error is discovered, a Kubernetes Event is generated and the relevant pod’s event stream is updated.  

The sample application executes this [code](https://github.com/box/error-reporting-with-kubernetes-events/blob/master/cmd/controlplane/main.go#L201) to setup the Kubernetes Event generation:  


```
// eventRecorder returns an EventRecorder type that can be  
// used to post Events to different object's lifecycles.  
func eventRecorder(  
   kubeClient \*kubernetes.Clientset) (record.EventRecorder, error) {  
   eventBroadcaster := record.NewBroadcaster()  
   eventBroadcaster.StartLogging(glog.Infof)  
   eventBroadcaster.StartRecordingToSink(  
      &typedcorev1.EventSinkImpl{  
         Interface: kubeClient.CoreV1().Events("")})  
   recorder := eventBroadcaster.NewRecorder(  
      scheme.Scheme,  
      v1.EventSource{Component: "controlplane"})  
   return recorder, nil  
}
 ```


After the one-time setup, the following [code](https://github.com/box/error-reporting-with-kubernetes-events/blob/master/cmd/controlplane/main.go#L163) generates events affiliated with pods:  

Title: Kubernetes Events vs. Status Web Page for Error Reporting and Code Example
Summary
This section elaborates on the comparison between using Kubernetes Events and a status web page for error reporting, ultimately favoring Kubernetes Events due to their ease of access through `kubectl describe`. It also provides a code snippet demonstrating how to set up Kubernetes Event generation, including creating an `EventRecorder` and broadcasting events. The code example shows how events are associated with pods, enabling clear error reporting within the Kubernetes ecosystem.