1

Forgive me for asking a stupid question but I can't seem to find anywhere in the Kubernetes API reference how to query logs via the REST API if there's more than one container running inside the pod?

cURL -k -H Authorization: Bearer my-super-secret-token https://kubernetes/api/v1/namespaces/default/pods/my-app-1/log

Returns:

{"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"a container name must be specified for pod my-app-1, choose one of: [nginx php-fpm]","reason":"BadRequest","code":400}

I tried:

cURL -k -H Authorization: Bearer my-super-secret-token https://kubernetes/api/v1/namespaces/default/pods/my-app-1/nginx/log

and it results in an error that the resource can't be found.

How do I specify the container name when making an HTTP request to the API?

Joel
  • 135
  • 9

1 Answers1

1

Figured it out - I needed to add container using a query parameter:

?container=nginx

Working Example:

cURL -k -H Authorization: Bearer my-super-secret-token https://kubernetes/api/v1/namespaces/default/pods/my-app-1/log?container=nginx

Joel
  • 135
  • 9
  • 1
    Also see the [`get` read log of the specified Pod](https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/pod-v1/#get-read-log-of-the-specified-pod) API documentation, which notes "container (in query)" for this option. – David Maze Oct 16 '22 at 10:33