April 2018
Intermediate to advanced
468 pages
14h 34m
English
Watching objects is an advanced capability. It is implemented using a separate watch module. Here is an example to watch for 10 namespace events and print them to the screen:
from kubernetes import client, config, watch# Configs can be set in Configuration class directly or using helper utilityconfig.load_kube_config()v1 = client.CoreV1Api()count = 10w = watch.Watch()for event in w.stream(v1.list_namespace, _request_timeout=60): print(f"Event: {event['type']} {event['object'].metadata.name}") count -= 1 if count == 0: w.stop()print('Done.')
Read now
Unlock full access