Kubernetes Log Fundamentals
Understanding Kubernetes Logging Architecture
Kubernetes logging is a critical mechanism for tracking and monitoring container and cluster events. In the context of container orchestration, logging provides insights into application performance, troubleshooting, and system health.
Log Generation Mechanisms
Kubernetes generates logs from multiple sources:
Log Source |
Description |
Container Logs |
Application-level logs from running containers |
Node Logs |
System-level logs from Kubernetes nodes |
Cluster Logs |
Kubernetes control plane and system component logs |
graph TD
A[Container Runtime] --> B[Container Logs]
C[Kubernetes Nodes] --> D[Node Logs]
E[Control Plane] --> F[Cluster Logs]
Basic Log Retrieval Commands
To retrieve logs in a Kubernetes environment, administrators can use kubectl commands:
## Retrieve logs from a specific pod
kubectl logs pod-name
## Stream live logs
kubectl logs -f pod-name
## Retrieve logs from a specific container in a multi-container pod
kubectl logs pod-name -c container-name
Log Storage and Management
Kubernetes stores logs temporarily on node filesystems, typically in /var/log/containers
directory. The default logging mechanism uses stdout and stderr streams, which are captured by container runtime.
Log Rotation Configuration
Ubuntu 22.04 manages log rotation through systemd and logrotate configurations:
## Check current log rotation settings
cat /etc/logrotate.d/docker-container
The logging architecture ensures efficient log management without overwhelming system storage resources.