Store Nginx Access Logs in Amazon CloudWatch with Logging Operator
This guide describes how to collect application and container logs in Kubernetes using the Logging operator, and how to send them to CloudWatch.
The following figure gives you an overview about how the system works. The Logging operator collects the logs from the application, selects which logs to forward to the output, and sends the selected log messages to the output. For more details about the Logging operator, see the Logging operator overview.
Deploy the Logging operator and a demo Application
Install the Logging operator and a demo application using Helm.
Deploy the Logging operator with Helm
To install the Logging operator using Helm, complete the following steps.
Note: You need Helm v3.8 or later to be able to install the chart from an OCI registry.
-
Install the Logging operator into the logging namespace:
Expected output:
Note:
-
Helm has a known issue in version 3.13.0 that requires users to log in to the registry, even though the repo is public.
Upgrade to 3.13.1 or higher to avoid having to log in, see: https://github.com/kube-logging/logging-operator/issues/1522
-
If you’re installing the Helm chart from Terraform, reference the repository as
repository = "oci://ghcr.io/kube-logging/helm-charts/"
(without thelogging-operator
suffix). Otherwise, you’ll get a 403 Forbidden error.
-
-
Create AWS
secret
If you have your
$AWS_ACCESS_KEY_ID
and$AWS_SECRET_ACCESS_KEY
set you can use the following snippet.Or set up the secret manually.
-
Create the
logging
resource.Note: You can use the
ClusterOutput
andClusterFlow
resources only in thecontrolNamespace
. -
Create an CloudWatch
output
definition.Note: In production environment, use a longer
timekey
interval to avoid generating too many objects. -
Create a
flow
resource. -
Install log-generator to produce logs with the label
app.kubernetes.io/name: log-generator
Validate the deployment
If you don’t get the expected result you can find help in the troubleshooting section.