I'm looking for the solution of how to get logs from a pod in Kubernetes cluster using golang. I've looked at "https://github.com/kubernetes/client-go" and "https://godoc.org/sigs.k8s.io/controller-runtime/pkg/client", but couldn't understand how to use them for this purpose. I have no issues getting information of a pod or any other object in K8S except for logs.
For example, I'm using Get() from "https://godoc.org/sigs.k8s.io/controller-runtime/pkg/client#example-Client--Get" to get K8S job info:
found := &batchv1.Job{}
err = r.client.Get(context.TODO(), types.NamespacedName{Name: job.Name, Namespace: job.Namespace}, found)
Please share of how you get pod's logs nowadays. Any suggestions would be appreciated!
Update: The solution provided in Kubernetes go client api for log of a particular pod is out of date. It have some tips, but it is not up to date with current libraries.
@Emixam23
I believe you will find this snippet useful.
How to get the dynamic name of a pod?
Here is what we came up with eventually using client-go library:
I hope it will help someone. Please share your thoughts or solutions of how you get logs from pods in Kubernetes.
The controller-runtime client library does not yet support subresources other than /status, so you would have to use client-go as shown in the other question.