Prepare your environment for this section:prepare-environment observability/logging/pods
This will make the following changes to your lab environment:
- Install AWS for Fluent Bit in the Amazon EKS cluster
You can view the Terraform that applies these changes here.\
According to the Twelve-Factor App manifesto, which provides the gold standard for architecting modern applications, containerized applications should output their logs to stdout and stderr. This is also considered best practice in Kubernetes and cluster level log collection systems are built on this premise.
The Kubernetes logging architecture defines three distinct levels:
kubectl logs myapp
– where myapp
is a pod running in my cluster)stdout
and stderr
, and writes them to a log file.Kubernetes, by itself, doesn’t provide a native solution to collect and store logs. It configures the container runtime to save logs in JSON format on the local filesystem. Container runtime – like Docker – redirects container’s stdout and stderr streams to a logging driver. In Kubernetes, container logs are written to /var/log/pods/*.log
on the node. Kubelet and container runtime write their own logs to /var/logs
or to journald, in operating systems with systemd. Then cluster-wide log collector systems like Fluentd can tail these log files on the node and ship logs for retention. These log collector systems usually run as DaemonSets on worker nodes.
In this lab, we’ll show how a log agent can be set up to collect logs from nodes in EKS and send them to CloudWatch Logs.
If you are using the CDK Observability Accelerator then check out the AWS for Fluent Bit Addon. AWS for FluentBit addon can be configured to forward logs to multiple AWS destinations including CloudWatch, Amazon Kinesis, and AWS OpenSearch.