<p>I am using client-go to continuouslly pull log streams from kubernetes pods. Most of the time everything works as expected, until the job runs couple of hours.</p>
<p>The code is like below:</p>
<pre><code>podLogOpts := corev1.PodLogOptions{ Follow: true, }
kubeJob, err := l.k8sclient.GetKubeJob(l.job.GetNamespace(), l.job.GetJobId())

...
podName := l.k8sclient.GetKubeJobPodNameByJobId(l.job.GetNamespace(), l.job.GetJobId())
req := l.k8sclient.GetKubeClient().CoreV1().Pods(l.job.GetNamespace()).GetLogs(podName, &amp;podLogOpts)
podLogStream, err := req.Stream(context.TODO())

...
for {
    copied, err := podLogStream.Read(buf)
    if err == io.EOF {
       // here is place where error happens
       // usually after many hours, the podLogStream return EOF.
       // I checked the pod status it is still running and keeps printing data to pod stdout. why would this happend???
       break
    }

    ...
}
</code></pre>
<p>The podLogStream returns EOF about 3-4 hours later. But I checked the pod status and found pod is still running and the service inside keeps printing data to the stdout. So why would this happend? How to fix it?</p>
<p><strong>UPDATE</strong>
I found that every 4 hours the pod stream api -- read -- would return EOF so I have to make the goroutine sleep and retry a second later, by recreating the pogLogStream and reading logs from new stream object. It works. But why would this happen??</p>

<p>When you contact logs endpoint what happens is that apiserver is forwarding your request to the kubelet which is hosting your pod. Kubelet server then start streaming content of the log file <a href="https://github.com/kubernetes/kubernetes/blob/985ac8ae5089d3312640b0fca795469fb8025f2a/pkg/kubelet/server/server.go#L666" rel="nofollow noreferrer">to the apiserver</a>  and later to your client. Since it is streaming logs from the file and <a href="https://github.com/kubernetes/kubernetes/blob/f0b7ad3ee06c5168fef5fa4f01fe445ece595f89/pkg/kubelet/kuberuntime/logs/logs.go#L280" rel="nofollow noreferrer">not from the stdout directly</a> it may happen that log file is rotated <a href="https://github.com/kubernetes/kubernetes/blob/f0b7ad3ee06c5168fef5fa4f01fe445ece595f89/pkg/kubelet/logs/container_log_manager.go#L66-L73" rel="nofollow noreferrer">by container log manager</a> and as consequence you receive EOF and need to reinitialize the stream.</p>
