Understanding Defaulted Container Error in Kubectl Logs
If you've ever worked with Kubernetes, you may have encountered the following error message when checking the logs of a container:
Defaulted container (
In this article, we'll dive into what this error message means, why it occurs, and how to troubleshoot it.
What is a Defaulted Container?
In Kubernetes, a defaulted container refers to a container that has not been explicitly specified for log collection. When you execute the kubectl logs command, Kubernetes will try to fetch logs from the main container of the pod. However, if there are multiple containers in a pod, or if the pod is created using a replicationController, deployment, or other higher-level objects, Kubernetes may not be able to determine which container's logs you want to see.
In this case, Kubernetes will default to the first container listed in the pod's specification. If that container has an init container, Kubernetes will display the defaulted container error message indicating that it has defaulted to the init container for log collection.
Why Does the Defaulted Container Error Occur?
The defaulted container error occurs due to one of the following reasons:
- Multiple containers in a pod
- Pods created using higher-level objects
- Container or init container not started
- Incorrect usage of the
kubectl logscommand
Let's take a closer look at each of these reasons.
Multiple Containers in a Pod
If a pod has multiple containers, the kubectl logs command will not know which container's logs to display. To avoid the defaulted container error message, you can specify the container name using the --container flag:
kubectl logs --container
Pods Created Using Higher-Level Objects
If you're using higher-level objects such as replicationController or deployment, the kubectl logs command will not know which pod to fetch logs from. In this case, you need to specify the pod name using the --selector or -l flag:
kubectl logs -l app=
Container or Init Container Not Started
If a container or init container in a pod has not started, the kubectl logs command will display the defaulted container error message. You can check the status of the pod's containers using the kubectl describe pod command:
kubectl describe pod
Incorrect Usage of the kubectl logs Command
If the kubectl logs command is not used correctly, it may display the defaulted container error message. For example, if you omit the pod name, container name, or selector, the command may not be able to locate the logs you want to see.
How to Troubleshoot the Defaulted Container Error
If you encounter the defaulted container error message, you can take the following steps to troubleshoot it:
- Check the pod specification to ensure that there is only one container or that the correct container name has been specified in the
kubectl logscommand. - Ensure that you're using the correct selector flag or label when fetching logs from higher-level objects.
- Check the status of the pod's containers using the
kubectl describe podcommand to ensure that they're running. - Verify the correct usage of the