Questão de Kubernetes Troubleshooting #019e3a4f
If kubectl is failing to retrieve information from the cluster, where can you find pod logs to troubleshoot?
/var/log/pods/
~/.kube/config
/var/log/k8s/
/etc/kubernetes/
Explicação Oficial / Explicações da Comunidade
When kubectl fails to retrieve information from the cluster, pod logs can be found in /var/log/pods/ on the node where the pod is running. This directory contains logs for each pod, organized by pod UID and container name. The correct location is /var/log/pods/ because Kubernetes stores container logs there by default when using the kubelet's logging mechanism.
How it Works
Kubernetes nodes run the kubelet, which manages pods and their containers. Container logs are written to stdout/stderr, and the kubelet captures these logs and stores them in /var/log/pods/. Each pod gets a subdirectory named after its UID, and within that, each container has its own log file (e.g., 0.log). This is the default location for container logs when using the json-file or journald logging driver.
Why the Correct Value is Right
/var/log/pods/is the default directory where kubelet stores container logs. Even ifkubectlcannot communicate with the API server, these logs are still accessible directly on the node. This makes it a reliable source for troubleshooting when cluster connectivity is broken.
Why the Incorrect Values are Wrong
~/.kube/configis the kubeconfig file that stores cluster access configuration (server address, credentials, context). It does not contain pod logs. Ifkubectlfails, this file might be misconfigured, but it is not a source of logs./var/log/k8s/is not a standard directory for Kubernetes logs. Some distributions may place cluster-level logs there, but pod logs are not stored in this path by default./etc/kubernetes/contains cluster configuration files (e.g., kubelet config, certificates, manifests). It does not contain pod logs. This directory is for static pod manifests and cluster bootstrap configuration, not runtime logs.