1

I would like to collect the logs from one or more related pods using a labelSelector and the kubernetes HTTP API. However, I don't see any way to do this without first knowing all the pods names, e.g.

{{baseUrl}}/api/v1/namespaces/:namespace/pods/:name/log?container=cillum &follow=true&insecureSkipTLSVerifyBackend=true&limitBytes=-94468552&pretty=cillum &previous=true&sinceSeconds=-94468552&tailLines=-94468552&timestamps=true

Is this possible, or should I mount a container with kubectl and use that to get the logs I want?

I can get the logs using kubectl like so:

kubectl logs -l job=myjob -n test -c main

I would assume there is a similar way to retrieve logs using the labelSelector using the API.

Ryan Riley
  • 11
  • 2
  • 2
    The answer to any "what api do I use for this kubectl thing?" is `kubectl --v=10 ...` which will show the `curl` equivalent for any action it takes. For your specific question, you'll observe that yes, one always needs the pod names for logs, but that using `-l` with logs merely does `k get po -o name -l ...` and _then_ does `k logs $that_name`; it's the same way `k exec deploy/some-deploy` works, because (obviously) one cannot really exec into a Deployment – mdaniel Nov 10 '22 at 20:18

0 Answers0