Joel
Joel

Reputation: 155

Kubernetes REST API - how to get pod logs when more than one container is running?

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?

Upvotes: 2

Views: 1075

Answers (1)

Joel
Joel

Reputation: 155

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

Upvotes: 1

Related Questions