Reputation: 409
I have the pod and it has 2 containers.
if i give the command "kubectl logs pod_name
"
it does not list logs, i need to give container name along with this command.
Is there a way to display both the container logs when we give command "kubectl logs pod_name
"?
Upvotes: 9
Views: 7177
Reputation: 142
If you want to follow the logs in real time, add -f
suffix.
kubectl logs -f <your-pod> --all-containers=true
Upvotes: 0
Reputation: 725
To display the logs of a particular container
kubectl logs <pod-name> -c <container_name>
To display all containers logs use below command
kubectl logs <pod-name> --all-containers=true
Upvotes: 17
Reputation: 44549
The rest API to get logs of a pod is
GET /api/v1/namespaces/{namespace}/pods/{name}/log
You can pass container as a query param to above API to get logs of a particular container
GET /api/v1/namespaces/{namespace}/pods/{name}/log?container=containername
When you hit above APIs from code using a service account or a user you need to have below RBAC Role
and RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
namespace: default
name: pod-logs-reader
rules:
- apiGroups: [""]
resources: ["pods/log"]
verbs: ["get", "list"]
The API is documented here
Upvotes: 1