Sumeet Poddar:
Someone please help me with the kubectl command to get containers in a pod
James Hilling:
I believe that kubectl describe pods/<pod-name> --namespace='<namespace-name>'
is the command you seek?
Sumeet Poddar:
Nooo James,
I want to see the logs that are being running in the containers in a pod, so before checking the logs on the containers, I need to know the container names that are running inside the pod.
James Hilling:
Ah I see
James Hilling:
are not the container names defined within the pod spec, i.e. pod.spec.conatiners.name ?
James Hilling:
If you want to know the container name?
James Hilling:
Then you use the container name to view the logs in the container
Sumeet Poddar:
Yeah wanna know the names of containers running inside the pod
James Hilling:
kubectl logs pods/<pod> <container-name-defined-within-the-pod-spec> --namespace=‘default’
James Hilling:
and the <container-name-defined-within-the-pod-spec> I can show you how to find using an example
James Hilling:
Here is my example YAML for a pod:
James Hilling:
Under the “spec:” field within the YAML you have the “containers:” field. Under the “containers:” field you have the “name:” field. This is the name of the container within the pod. For example one container is called “nginx” the other is called “curl”. To see logs for the “curl” pod (id any exist) I would run:
James Hilling:
kubectl logs pods/nginx-and-curl curl --namespace='default'
Sumeet Poddar:
Yes James I got your point… Describe pod command shows the containers inside it… But that’s a long way…as mentioned in the last solution video under the logging and monitoring section there’s a command to display just the containers inside pod
Kubectl logs nginx -c
But this command is not working when I try
Sumeet Poddar:
Anyways I will use the describe command as you suggested, for now that will do my work
James Hilling:
This worked for me:
James Hilling:
kubectl logs pods/nginx-and-curl -c curl -n default
Sumeet Poddar:
Cool