Akash Shinde
Akash Shinde

Reputation: 131

Read logs from kubernetes pod from last read point

I want to read data from k8s pod either in form of logs or log file. I want to read it after specific time interval but from last read point. Previous data should not be repeated. Currently, for pod logs I am using watchLog:

LogWatch logWatch =client.pods()
                    .inNamespace(namespace)
                    .withName(podName)
                    .sinceSeconds(10).watchLog();

above code gives me all logs from the beginning every time.

Also, I am trying to read application specific log file as below:

InputStream is = client.pods()
                  .inNamespace(namespace)
                  .withName(podName)
                  .file("/app/logs/demo.log")
                  .read())  {
                    String result = new BufferedReader(new 

InputStreamReader(is)).lines().collect(Collectors.joining("\n"));
                        System.out.println("> "+result);
            

same issue with reading file as well.

How can I get latest logs/data using fabric8 client?

Upvotes: 0

Views: 173

Answers (1)

Akash Shinde
Akash Shinde

Reputation: 131

There is no direct option and hence I used Runtime util from Java to execute tail command.

Upvotes: 0

Related Questions