Cannot retrieve POD logs in go client while available from kubectl logs command

8/17/2017

In our Kubernetes, there is a POD which is restarting continuously.

If I use kubectl logs -p POD_NAME -n NAMESPACE command I get detailed log. However when we use the go client for kubernetes and try to retrieve the log, we get nothing.

We are using GetLogs(name string, opts *v1.PodLogOptions) method of PodExpansion inteface.

I also tried using various options in PodLogOptions, for eg. sinceSeconds=BeginningOfTheYear but no luck.

Any help is deeply appreciated.

-- Rajdeep Sardar
deployment
go
kubernetes
kubernetes-go-client

2 Answers

8/17/2017

The question is too general without much info, so I guess is this answer. The repeated restarting of the pod is due to pod failure. Kubernetes restarts the pods as it fails until it gets the pod working, which unfortunately, it doesn't gets in this case.

This can happen due to various reasons. Some may be due to resource problems, environment variables being loosely connected etc. I always hover over the logs for this kind of problems, and also do check the kubectl describe pods <pod_name> command, and watch over the few last lines. They show the current actions taking place and the reason for failure. This might help.

-- Akash
Source: StackOverflow

8/17/2017

We found a reason. There is some error in our side of the SourceCode. We were checking if POD is not Running just return. But in this case POD is in Waiting State as it can not get started.

We had to add this part of the code to avoid the log collection from the POD from Blocking.

-- Rajdeep Sardar
Source: StackOverflow