Pods with more than one container

Our examples have been simple so far, with a single container in a Pod. A Pod can have more than one container at a time, and the command to get the logs can specify which container to use. If there is only one container, you don’t need to specify which one to use.

If you need to specify a specific container, you can do so with either the -c option, or by adding it onto the logs command. For example, if you had a Pod named webapp with two containers, flask and background, and you wanted to see the logs from the background container, you could use the kubectl logs webapp background or kubectl logs webapp -c background commands.

Likewise, there's a shortcut for defining Pods and containers within a deployment. Rather than specifying the full Pod name based on the names assigned through Kubernetes, you can prefix the name of the Pod with just the deployment name. For example, if we had created a deployment with the kubectl run flask image=… command from our earlier examples, we could use the following command:

kubectl logs deployment/flask

This is rather than looking up the specific Pod name and then asking for the logs based on that name.