How to continuously display live Kubernetes pods logs on a flask UI?

1/31/2020

I want to display live logs of a Kubernetes pod on a web page in flask. I have a process running and want to display its current state on a webpage for a user. For that I want the live logs to be displayed on the UI.

-- arush saxena
docker
flask
kubernetes
logging
pod

1 Answer

1/31/2020

The core API for this is part of the Pods API: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.17/#read-log-pod-v1-core

You would want to provide the follow option. This does appear to be supported by the Python client library, however it's a blocking operation so you would need to find some async-y way to return that stream to your web client (websockets perhaps) and write some javascript to display it.

This is not going to be a simple thing, as is often the case with nested async APIs.

-- coderanger
Source: StackOverflow