'Kubernetes events - how to get continuous stream of events?

I was reading about Kubernetes events and it seems the only way to process events is to create a Watch over http call, which in turn processes the response and becomes Iterator of events. But that is finite and you have to recreate the event watch constantly... Is there a way to simply tail events with some callback, in Java?



Solution 1:[1]

As a native watching method for Kubernetes, you can watch events in real-time with --watch flag - it is a part of API server, allowing to fetch the current state of resource/object and then subscribe to subsequent changes:

kubectl get events --watch

There is no in-built solution in Kubernetes for storing/forward event objects on the long term as by default the events have a 1-hour life span. You would need to use third-party tools to stream the events continuously, e.g. - Kubernetes Event Exporter; to collect them and export to external systems for alerting/further processing - e.g. kubewatch, kubernetes-event-exporter tools.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 anarxz