so I am using the following kubernetes HTTP API to try to stream the logs of a currently running pod in my kubernetes cluster (I don't want to use kubectl as I need to call this API from application code):
GET /api/v1/namespaces/{namespace}/pods/{name}/log
It's documented here https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.10/#read-log
I am passing the "follow=true" parameter in the API call as I basically want to send a request to the kubernetes API, keep the connection open and have the kubernetes API continually send me back the logs, bit by bit. When I use kubectl to do the same thing, I used the verbose option and I discovered that all it really does is send one request using the above API (with follow=true), and the logs get streamed back.
When kubectl does this, it just sends one request like the above and it's able to stream it back, and it's not using transfer encoding chunked or anything like that... How can I emulate this from application level code? When I try to do this in my application code (I am using java), it waits for the request to complete fully before it can print out the logs. For reference here is my code:
PodLogStreamer podLogStreamer = new PodLogStreamer();
InputStream is = podLogStreamer
.getLogStream("asdf", "asdfasd", "asdfas");
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(is));
String line;
while ((line = bufferedReader.readLine()) != null && !line.equals("ENDLOGS")) {
System.out.println(line);
Thread.sleep(100);
}
bufferedReader.close();
PodLogStreamer() is a class that I made which just calls the API above in the way I mentioned earlier. IS there a way to request from the client side that the kubernetes API server should maintain a persistent connection and stream the logs back?