Use `kubectl logs POD` to read a container’s stdout and stderr when a pod starts, crashes, or behaves unexpectedly. First find the pod with `kubectl get po`; then use its log output to identify an error you can act on. section 8.1 section 8.1.1
Find a crash-loop cause
A MySQL pod shows `CrashLoopBackOff`. Running `kubectl logs mysql-68f7776797-w92l6` reveals that the database is uninitialized and no password option is set. Add an indicated password environment variable to the Deployment, then check `kubectl get po` for a running replacement pod. section 8.1
Choose the scope of the logs you need:
- For one container in a multi-container pod, specify its name: `kubectl logs busybox -c sidecar`. Use `-c busybox` to inspect the other container. section 8.1.1
- To retrieve logs from every container in that pod, run `kubectl logs busybox --all-containers`. section 8.1.1
- For a pod outside the current namespace, specify the namespace: `kubectl logs kube-controller-manager-server1 -n kube-system`. section 1.8
Container stdout and stderr are sent to log files managed by kubelet under `/var/log/containers`; `kubectl logs` is the usual way to retrieve pod logs. Do not confuse them with node and service logs: use `journalctl` to investigate processes such as kubelet or containerd. When investigating pod errors, `kubectl describe po` also supplies container state and events. section 8.1 section 8.1.1 section 1.8
Investigate a control-plane failure
If new Deployment replicas remain `Pending`, inspect the relevant control-plane pod in `kube-system`. In a scheduler failure, `kubectl -n kube-system logs kube-scheduler-kind-control-plane` exposes `Error: unknown flag: --kkubeconfig`; the scheduler’s static-pod manifest is the place to investigate the bad command. section 8.2
root@kind-control-plane:/# kubectl logs mysql-68f7776797-w92l6
2022-12-04 16:51:13+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL
Server 8.0.31-1.el8 started.
2022-12-04 16:51:13+00:00 [Note] [Entrypoint]: Switching to dedicated user
'mysql'
2022-12-04 16:51:13+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL
Server 8.0.31-1.el8 started.
2022-12-04 16:51:13+00:00 [ERROR] [Entrypoint]: Database is uninitialized
and password option is not specified
You need to specify one of the following as an environment variable:
- MYSQL_ROOT_PASSWORD
- MYSQL_ALLOW_EMPTY_PASSWORD
- MYSQL_RANDOM_ROOT_PASSWORD
The MySQL log output names the missing password configuration and the environment-variable options, making the next repair concrete. section 8.1


