python kubernetes watch pod logs not working

8/5/2019

Trying to use the python kubernetes API to stream the output of kubernetes pod logs. (eventual goal is to stream the logs out via websocket)

Based off this PR that was merged into python kubernetes module, i thought watch would work with read_namespaced_pod_log?

v1 = client.CoreV1Api()
w = watch.Watch()
for e in w.stream(v1.read_namespaced_pod_log, name=pod, namespace=namespace, follow=True, tail_lines=1, limit_bytes=560, _preload_content=False):
   print(e)

But i get the error below, am i missing something that needs to be passed to watch? or read_namespaced_pod_log?

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.7/site-packages/kubernetes/watch/watch.py", line 132, in stream
    resp = func(*args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/kubernetes/client/apis/core_v1_api.py", line 18538, in read_namespaced_pod_log
    (data) = self.read_namespaced_pod_log_with_http_info(name, namespace, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/kubernetes/client/apis/core_v1_api.py", line 18576, in read_namespaced_pod_log_with_http_info
    " to method read_namespaced_pod_log" % key
TypeError: Got an unexpected keyword argument 'watch' to method read_namespaced_pod_log
-- BLang
kubernetes
python

1 Answer

8/5/2019

You should just do:

v1 = client.CoreV1Api()
w = Watch()
for e in w.stream(v1.read_namespaced_pod_log, name=pod, namespace=namespace):
    print(e)
-- Mitar
Source: StackOverflow