0

Using the kubernetes Python API< you have to specify the events to watch? Is it possible to watch all events in the cluster

clout_chaser
  • 3
  • 1
  • 6

2 Answers2

1

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.

Oron Golan
  • 361
  • 1
  • 13
1

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.

amitection
  • 2,696
  • 8
  • 25
  • 46