Using the kubernetes Python API< you have to specify the events to watch? Is it possible to watch all events in the cluster
From what I understand you are looking for this.
import kubernetes as k8s
core_api = k8s.client.CoreV1Api()
watcher = k8s.watch.Watch()
stream = watcher.stream(core_api.list_event_for_all_namespaces, timeout_seconds=5)
for raw_event in stream:
logging.info("Kubernetes Event: %s %s" % (raw_event['type'],raw_event['object'].metadata.name))
I haven't tested the snippet, but it should work.
Yes.
I am pretty sure that there is a library of Python that already implement this but in my case i implement it using the command: --watch-only
For example: kubectl get pods --watch-only > -> will show only the changes in pods. Creating python process that collect the info from the will trigger only new changes.