Browse the Repo

file-type-icon.circleci
file-type-icon_docs
file-type-iconexamples
file-type-iconmodules
file-type-iconeks-alb-ingress-controller-iam-policy
file-type-iconeks-alb-ingress-controller
file-type-iconeks-cloudwatch-container-logs
file-type-icontemplates
file-type-iconREADME.md
file-type-iconmain.tf
file-type-iconoutputs.tf
file-type-iconvariables.tf
file-type-iconeks-cluster-control-plane
file-type-iconeks-cluster-managed-workers
file-type-iconeks-cluster-workers-cross-access
file-type-iconeks-cluster-workers
file-type-iconeks-iam-role-assume-role-policy-for-servic...
file-type-iconeks-k8s-cluster-autoscaler-iam-policy
file-type-iconeks-k8s-cluster-autoscaler
file-type-iconeks-k8s-external-dns-iam-policy
file-type-iconeks-k8s-external-dns
file-type-iconeks-k8s-role-mapping
file-type-iconeks-scripts
file-type-iconeks-vpc-tags
file-type-iconrfc
file-type-icontest
file-type-icon.gitignore
file-type-icon.pre-commit-config.yaml
file-type-iconCODEOWNERS
file-type-iconCONTRIBUTING.md
file-type-iconGRUNTWORK_PHILOSOPHY.md
file-type-iconLICENSE.md
file-type-iconREADME.adoc
file-type-iconcore-concepts.md
file-type-iconsetup.cfg

Browse the Repo

file-type-icon.circleci
file-type-icon_docs
file-type-iconexamples
file-type-iconmodules
file-type-iconeks-alb-ingress-controller-iam-policy
file-type-iconeks-alb-ingress-controller
file-type-iconeks-cloudwatch-container-logs
file-type-icontemplates
file-type-iconREADME.md
file-type-iconmain.tf
file-type-iconoutputs.tf
file-type-iconvariables.tf
file-type-iconeks-cluster-control-plane
file-type-iconeks-cluster-managed-workers
file-type-iconeks-cluster-workers-cross-access
file-type-iconeks-cluster-workers
file-type-iconeks-iam-role-assume-role-policy-for-servic...
file-type-iconeks-k8s-cluster-autoscaler-iam-policy
file-type-iconeks-k8s-cluster-autoscaler
file-type-iconeks-k8s-external-dns-iam-policy
file-type-iconeks-k8s-external-dns
file-type-iconeks-k8s-role-mapping
file-type-iconeks-scripts
file-type-iconeks-vpc-tags
file-type-iconrfc
file-type-icontest
file-type-icon.gitignore
file-type-icon.pre-commit-config.yaml
file-type-iconCODEOWNERS
file-type-iconCONTRIBUTING.md
file-type-iconGRUNTWORK_PHILOSOPHY.md
file-type-iconLICENSE.md
file-type-iconREADME.adoc
file-type-iconcore-concepts.md
file-type-iconsetup.cfg
EC2 Kubernetes Service (EKS) Cluster

EC2 Kubernetes Service (EKS) Cluster

Deploy a Kubernetes cluster on top of Amazon EC2 Kubernetes Service (EKS).

Code Preview

Preview the Code

mobile file icon

README.md

down

EKS CloudWatch Container Logs Module

This Terraform Module installs and configures fluentd-cloudwatch on an EKS cluster, so that each node runs fluentd to collect the logs and ship to CloudWatch.

This module uses the community helm chart, with a set of best practices inputs.

How does this work?

This module solves the problem of unifying the log streams in your Kubernetes cluster to be shipped to CloudWatch so that you have a single interface to search and monitor your logs. To achieve this, the module installs a service (fluentd) that monitors the log files on the filesystem, parses custom log formats into a unified format, and ships the result to a centralized log aggregation service (CloudWatch).

fluentd is installed as a Kubernetes DaemonSet, which ensures that there is one fluentd Pod running per node. In this way, we are able to ensure that all workers in the cluster are running the fluentd service for shipping the logs into CloudWatch.

You can read more about fluentd in their official home page. You can also learn more about CloudWatch logging in the official AWS docs.

How do you use this module?

Prerequisites

Helm setup

This module uses helm v3 to deploy fluentd to the Kubernetes cluster.

Cloudwatch Log Group

This module assumes the log group you would like to use already exists. You can use the cloudwatch_log_group resource to create a new log group in Terraform. For example:

resource "aws_cloudwatch_log_group" "eks_cluster" {}

This will create a new log group and assign a random unique name that you can then access using aws_cloudwatch_log_group.eks_cluster.name.

IAM permissions

The container deployed in this module requires IAM permissions to access log streams in CloudWatch so that it can write logs to it. Below is a sample IAM policy statement that grants the minimal set of permissions:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "logs",
            "Effect": "Allow",
            "Action": [
                "logs:CreateLogStream",
                "logs:PutLogEvents",
                "logs:DescribeLogGroups",
                "logs:DescribeLogStreams"
            ],
            "Resource": [
                "arn:aws:logs:*:*:*"
            ]
        }
    ]
}

Differences with CloudWatch Container Insights

AWS CloudWatch Container Insights is a set of Kubernetes applications that run on your EKS cluster to collect metrics and log entries to ship to CloudWatch. This is handled by deploying the CloudWatch Agent and FluentD as DaemonSets that run on each node to watch the metrics and log entries.

This module also uses FluentD as a DaemonSet under the hood. However, there are a few differences in the setup:

  • This module is only scoped to collect the container logs. CloudWatch Container Insights on the other hand will observe all logs on the server.
  • This module does not set up the CloudWatch Agent for collecting cluster metrics, and is only concerned with log entries. CloudWatch Container Insights also includes observing cluster and pod metrics.

Questions? Ask away.

We're here to talk about our services, answer any questions, give advice, or just to chat.

Ready to hand off the Gruntwork?