How can I send container log files to CloudWatch?

0
18
Asked By TechieCat123 On

I'm working with a WebSphere Liberty application that's deployed on EKS. The app generates info, error, and debug logs in .log files within the container. We've set up Fluent Bit as a daemon set but so far, we've only been able to send the logs visible through the command 'kubectl logs pod_name -n namespace_name'. However, I need to get the logs from the .log files to CloudWatch. Given that we have 40 applications, each with logs saved in different paths inside their containers, how can I accomplish this?

3 Answers

Answered By KubeNinja On

The shared volume is vital for reading the log files, so make sure you have that set up properly. Here's a quick example of how your deployment should look, including specifying the paths:
```yaml
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: fluent-bit
spec:
template:
spec:
containers:
- name: fluent-bit
image: aws-for-fluent-bit:latest
volumeMounts:
- name: logs
mountPath: /opt/myapp/logs
volumes:
- name: logs
hostPath:
path: /opt/myapp/logs
```
Make sure that the Fluent Bit config is set correctly to match the log paths in your applications.

Answered By CloudWatchWiz On

You could also consider running Fluent Bit as a sidecar in your containers. This way, it can collect logs directly from where they are written. But just a heads up, logging directly inside the container isn't the best practice for long-lasting applications. Ideally, you’d want to adjust the app to log to stdout or to an OTEL endpoint instead.

LegacyAppDev -

I tried directing the logs to stdout, but the outputs from the .log files didn’t show up with 'kubectl logs'. What should I do?

Answered By LogGuru99 On

Fluent Bit operates from the host nodes and not directly within the application containers. If there's no shared volume set up, Fluent Bit can't access the log files inside the containers. It looks like you've tried using hostPath to create a shared volume; that's essential for Fluent Bit to gather the logs. Ensure that the shared volume is correctly configured so Fluent Bit can read from it. Let me know how it goes!

AppLogHacker -

We've set up the shared volume and confirmed the directories are created on the nodes, but unfortunately, the logs still aren’t being pushed to CloudWatch. Any idea what else could be wrong?

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.