Skip to content

Commit 1f91205

Browse files
authored
Update module to use the new container insights with CW for EKS (#252)
* Adding Module and Example for ECS cluster monitoring with ecs_observer * Adding Module and Example for ECS cluster monitoring with ecs_observer * Incorporating PR comments * Restructuring Examples and modules folder for ECS, Added content in main Readme * Fixing path as per PR comments * Parameterzing the config files, incorporated PR review comments * Adding condition for AMP WS and fixing AMP endpoint * Adding Document for ECS Monitoring and parameterized some variables * Added sample dashboard * Adding Document for ECS Monitoring and parameterized some variables * Fixing failures detected by pre-commit * Fixing failures detected by pre-commit * Fixing failures detected by pre-commit * Pre-commit fixes * Fixing failures detected by pre-commit * Fixing failures detected by pre-commit * Pre-commit * Fixing HIGH security alerts detected by pre-commit * Fixing HIGH security alerts detected by pre-commit * Fixing HIGH security alerts detected by pre-commit, 31stOct * Add links after merge * 2ndNov - Added condiotnal creation for Grafana WS and module versions for AMG, AMP * Module to use the new container insights with CW for EKS * Module to use the new container insights with CW for EKS * Fixing precommit error * Updating EKS container insights to replace deamonset with tf resource * Updating EKS container insights to replace deamonset with tf resource * Updating EKS container insights to replace deamonset with tf resource * Updating EKS container insights to replace deamonset with tf resource * Updating EKS container insights- Adding doc and fixing pre-commit errors * Update Images in the doc * Update data.tf pre-commit error * Apply suggestions from code review * fixing broken hyperlink * EKS Container Insights - updating docs and few varibaleable names, definitions
1 parent 2ecdcd1 commit 1f91205

File tree

14 files changed

+190
-255
lines changed

14 files changed

+190
-255
lines changed

docs/container-insights/eks.md

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# Setting Up Container Insights for your EKS Cluster
22

3-
This example deploys AWS Distro of OpenTelemetry on your EKS cluster as a Daemonset which will enable
4-
Container Insights metrics Dashboard on Amazon CloudWatch.
3+
This example deploys CloudWatch Observability EKS add-on on an exisiting Amazon EKS cluster, which enables Container Insights enhanced observability for Amazon EKS and CloudWatch Application Signals by default.
54

5+
1. Enables the CloudWatch Observability Add-on on EKS using the IAM service account role
6+
2. Creates an IAM Service Linked role for enabling Application Signals
67

78
## Prerequisites
89

@@ -34,6 +35,16 @@ Specify the EKS Cluster Name where the resources will be deployed:
3435
export TF_VAR_eks_cluster_id=xxx
3536
```
3637

38+
### 3. Disable creation of `Cloudwatch Application Signals Service-linked Role`
39+
If you already have Application Signals deployed in your AWS account, please set the value of this variable to `false`
40+
```
41+
variable "create_cloudwatch_application_signals_role" {
42+
type = bool
43+
default = true
44+
description = "Create a Cloudwatch Application Signals service-linked role"
45+
}
46+
```
47+
3748
## Deploy
3849

3950
Simply run this command to deploy the example
@@ -42,12 +53,40 @@ Simply run this command to deploy the example
4253
terraform apply
4354
```
4455

45-
## Visualization
56+
## Enabling Application Signals (preview) for your services
57+
CloudWatch Application Signals (preview) is currenlty supported for **Java** applications running on your Amazon EKS cluster.
58+
59+
Next, you have to update your Application to `Configure application metrics and trace sampling`. For this, you must add an annotation to a manifest YAML in your cluster. Adding this annotation auto-instruments the application to send metrics, traces, and logs to Application Signals. You have two options for the annotation:
60+
61+
1. **Annotate Workload** auto-instruments a single workload in the cluster.
62+
- Paste the below line into the PodTemplate section of the workload manifest.
63+
```
64+
annotations: instrumentation.opentelemetry.io/inject-java: "true"
65+
```
66+
- In your terminal, enter `kubectl apply -f your_deployment_yaml` to apply the change.
67+
68+
2. **Annotate Namespace** auto-instruments all workloads deployed in the selected namespace.
69+
- Paste the below line into the metadata section of the namespace manifest.
70+
```
71+
annotations: instrumentation.opentelemetry.io/inject-java: "true"
72+
```
73+
- In your terminal, enter `kubectl apply -f your_namespace_yaml` to apply the change.
74+
- In your terminal, enter a command to restart all pods in the namespace. An example command to restart deployment workloads is `kubectl rollout restart deployment -n namespace_name`
75+
76+
## Visualization of Container Insights data
77+
78+
After `terraform apply` is successful, open your Amazon CloudWatch console in the same region as your EKS cluster, then from the left hand side choose `Insights -> Container Insights`, there choose the `EKS` from the drop down and you will see the metrics shown on the dashboard:
79+
80+
<img width="1345" alt="image" src="https://github.com/ruchimo/terraform-aws-observability-accelerator/assets/106240341/31686b29-8ec2-46ff-a266-ebfa1de9768a">
81+
82+
83+
## Visualization of CloudWatch Application Signals (preview) data
4684
47-
After apply, open your Amazon CloudWatch console in the same region as your EKS cluster, then from the left hand side choose `Insights -> Container Insights`, there choose the `Performance montoring` from the drop down, choose the `cluster name` and you will see the metrics shown on the dashboard:
85+
After enabling your Application to pass metrics and traces by following [the steps provided above](#enabling-application-signals-preview-for-your-services), open your Amazon CloudWatch console in the same region as your EKS cluster, then from the left hand side choose `Application Signals -> Services` and you will see the metrics shown on the sample dashboard below:
4886
49-
![image](https://github.com/aws-observability/terraform-aws-observability-accelerator/assets/10175027/c5b9b685-5894-4350-b68a-ca86d1128f6f)
87+
<img width="1321" alt="image" src="https://github.com/ruchimo/terraform-aws-observability-accelerator/assets/106240341/2fccf784-6560-45a9-8be0-4e843c9653f1">
5088
89+
<img width="1300" alt="image" src="https://github.com/ruchimo/terraform-aws-observability-accelerator/assets/106240341/69749d78-7c9a-4019-a023-f5412ab3b2de">
5190
5291
## Cleanup
5392

examples/eks-container-insights/README.md

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
# Enable Container Insights for EKS cluster
22

3-
This example deploys ADOT as a daemonset on your EKS cluster which enables Container Insights metrics on CloudWatch.
4-
5-
Step-by-step instructions available on our [docs site](https://aws-observability.github.io/terraform-aws-observability-accelerator/)
6-
under **Amazon CloudWatch Container Insights**
3+
This example enables enhanced CloudWatch Container Insights for EKS and CloudWatch Application Signals (preview) through our CloudWatch EKS add-ons, providing comprehensive metrics, logs, and insights for cluster and application monitoring.
74

5+
Step-by-step instructions available on our [docs site](https://aws-observability.github.io/terraform-aws-observability-accelerator/container-insights/eks/)
86

97
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
108
## Requirements
@@ -13,9 +11,6 @@ under **Amazon CloudWatch Container Insights**
1311
|------|---------|
1412
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.1.0 |
1513
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.0.0 |
16-
| <a name="requirement_helm"></a> [helm](#requirement\_helm) | >= 2.4.1 |
17-
| <a name="requirement_kubectl"></a> [kubectl](#requirement\_kubectl) | >= 2.0.3 |
18-
| <a name="requirement_kubernetes"></a> [kubernetes](#requirement\_kubernetes) | >= 2.10 |
1914

2015
## Providers
2116

@@ -42,10 +37,11 @@ under **Amazon CloudWatch Container Insights**
4237

4338
| Name | Description | Type | Default | Required |
4439
|------|-------------|------|---------|:--------:|
45-
| <a name="input_aws_region"></a> [aws\_region](#input\_aws\_region) | EKS cluster region | `string` | n/a | yes |
40+
| <a name="input_eks_cluster_domain"></a> [eks\_cluster\_domain](#input\_eks\_cluster\_domain) | The domain for the EKS cluster | `string` | `""` | no |
4641
| <a name="input_eks_cluster_id"></a> [eks\_cluster\_id](#input\_eks\_cluster\_id) | EKS cluster name | `string` | n/a | yes |
47-
| <a name="input_irsa_iam_permissions_boundary"></a> [irsa\_iam\_permissions\_boundary](#input\_irsa\_iam\_permissions\_boundary) | IAM permissions boundary for IRSA roles | `string` | `null` | no |
48-
| <a name="input_irsa_iam_role_path"></a> [irsa\_iam\_role\_path](#input\_irsa\_iam\_role\_path) | IAM role path for IRSA roles | `string` | `"/"` | no |
42+
| <a name="input_eks_cluster_version"></a> [eks\_cluster\_version](#input\_eks\_cluster\_version) | The Kubernetes version for the cluster | `string` | `"1.28"` | no |
43+
| <a name="input_eks_oidc_provider"></a> [eks\_oidc\_provider](#input\_eks\_oidc\_provider) | The OpenID Connect identity provider (issuer URL without leading `https://`) | `string` | `null` | no |
44+
| <a name="input_eks_oidc_provider_arn"></a> [eks\_oidc\_provider\_arn](#input\_eks\_oidc\_provider\_arn) | The OpenID Connect identity provider ARN | `string` | `null` | no |
4945
| <a name="input_tags"></a> [tags](#input\_tags) | Additional tags (e.g. `map('BusinessUnit`,`XYZ`) | `map(string)` | `{}` | no |
5046

5147
## Outputs
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
data "aws_partition" "current" {}
2+
data "aws_caller_identity" "current" {}
3+
data "aws_region" "current" {}
4+
5+
data "aws_eks_cluster" "eks_cluster" {
6+
name = var.eks_cluster_id
7+
}
Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
1-
data "aws_partition" "current" {}
1+
locals {
2+
name = "amazon-cloudwatch-observability"
3+
eks_oidc_issuer_url = replace(data.aws_eks_cluster.eks_cluster.identity[0].oidc[0].issuer, "https://", "")
24

3-
data "aws_caller_identity" "current" {}
5+
addon_context = {
6+
aws_caller_identity_account_id = data.aws_caller_identity.current.account_id
7+
aws_caller_identity_arn = data.aws_caller_identity.current.arn
8+
aws_partition_id = data.aws_partition.current.partition
9+
aws_region_name = data.aws_region.current.name
10+
eks_oidc_provider_arn = "arn:${data.aws_partition.current.partition}:iam::${data.aws_caller_identity.current.account_id}:oidc-provider/${local.eks_oidc_issuer_url}"
11+
eks_cluster_id = data.aws_eks_cluster.eks_cluster.id
12+
tags = var.tags
13+
}
414

5-
data "aws_region" "current" {}
6-
7-
data "aws_eks_cluster" "eks_cluster" {
8-
name = var.eks_cluster_id
15+
addon_config = {
16+
kubernetes_version = var.eks_cluster_version
17+
most_recent = true
18+
}
919
}
Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,8 @@
1-
provider "aws" {
2-
region = var.aws_region
3-
}
4-
5-
provider "kubernetes" {
6-
host = local.eks_cluster_endpoint
7-
cluster_ca_certificate = base64decode(data.aws_eks_cluster.eks_cluster.certificate_authority[0].data)
8-
exec {
9-
api_version = "client.authentication.k8s.io/v1beta1"
10-
args = ["eks", "get-token", "--cluster-name", var.eks_cluster_id]
11-
command = "aws"
12-
}
13-
}
14-
15-
provider "helm" {
16-
kubernetes {
17-
host = local.eks_cluster_endpoint
18-
cluster_ca_certificate = base64decode(data.aws_eks_cluster.eks_cluster.certificate_authority[0].data)
19-
exec {
20-
api_version = "client.authentication.k8s.io/v1beta1"
21-
args = ["eks", "get-token", "--cluster-name", var.eks_cluster_id]
22-
command = "aws"
23-
}
24-
}
25-
}
26-
27-
28-
# Deploy the ADOT Container Insights
29-
301
module "eks_container_insights" {
31-
source = "../../modules/eks-container-insights"
32-
# source = "github.com/aws-observability/terraform-aws-observability-accelerator//modules/eks-container-insights?ref=v2.5.4"
33-
eks_cluster_id = var.eks_cluster_id
2+
source = "../../modules/eks-container-insights"
3+
eks_cluster_id = var.eks_cluster_id
4+
enable_amazon_eks_cw_observability = true
5+
create_cloudwatch_observability_irsa_role = true
6+
eks_oidc_provider_arn = local.addon_context.eks_oidc_provider_arn
7+
create_cloudwatch_application_signals_role = true
348
}

examples/eks-container-insights/variables.tf

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,30 @@ variable "eks_cluster_id" {
33
type = string
44
}
55

6-
variable "aws_region" {
7-
description = "EKS cluster region"
6+
variable "eks_cluster_domain" {
7+
description = "The domain for the EKS cluster"
88
type = string
9+
default = ""
910
}
1011

11-
variable "irsa_iam_role_path" {
12-
description = "IAM role path for IRSA roles"
12+
variable "eks_oidc_provider" {
13+
description = "The OpenID Connect identity provider (issuer URL without leading `https://`)"
1314
type = string
14-
default = "/"
15+
default = null
1516
}
1617

17-
variable "irsa_iam_permissions_boundary" {
18-
description = "IAM permissions boundary for IRSA roles"
18+
variable "eks_oidc_provider_arn" {
19+
description = "The OpenID Connect identity provider ARN"
1920
type = string
2021
default = null
2122
}
2223

24+
variable "eks_cluster_version" {
25+
description = "The Kubernetes version for the cluster"
26+
type = string
27+
default = "1.28"
28+
}
29+
2330
variable "tags" {
2431
description = "Additional tags (e.g. `map('BusinessUnit`,`XYZ`)"
2532
type = map(string)

examples/eks-container-insights/versions.tf

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,5 @@ terraform {
66
source = "hashicorp/aws"
77
version = ">= 5.0.0"
88
}
9-
kubernetes = {
10-
source = "hashicorp/kubernetes"
11-
version = ">= 2.10"
12-
}
13-
kubectl = {
14-
source = "alekc/kubectl"
15-
version = ">= 2.0.3"
16-
}
17-
helm = {
18-
source = "hashicorp/helm"
19-
version = ">= 2.4.1"
20-
}
219
}
22-
23-
# ## Used for end-to-end testing on project; update to suit your needs
24-
# backend "s3" {
25-
# bucket = "aws-observability-accelerator-terraform-states"
26-
# region = "us-west-2"
27-
# key = "e2e/eks_container_insights/terraform.tfstate"
28-
# }
29-
3010
}

modules/eks-container-insights/README.md

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
# Container Insights ADOT implementation for EKS Cluster Observability
1+
# Container Insights CloudWatch implementation for EKS Cluster Observability
22

3-
This module provides an automated experience around enabling Container Insights for your EKS cluster using ADOT (AWS Distro for OpenTelemetry).
4-
It provides the following resources:
3+
This module configures AWS CloudWatch Agent used for CloudWatch Application signals and Container Insights.
54

6-
- ADOT Collector Deployment to your EKS cluster
7-
- Enabling Container Insights on CloudWatch
5+
Use CloudWatch Application Signals to automatically instrument your applications on AWS so that you can monitor current application health and track long-term application performance against your business objectives. Application Signals provides you with a unified, application-centric view of your applications, services, and dependencies, and helps you monitor and triage application health.
6+
7+
Use CloudWatch Container Insights to collect, aggregate, and summarize metrics and logs from your containerized applications and microservices. CloudWatch automatically collects metrics for many resources, such as CPU, memory, disk, and network. Container Insights also provides diagnostic information, such as container restart failures, to help you isolate issues and resolve them quickly. You can also set CloudWatch alarms on metrics that Container Insights collects.
88

99

1010
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
@@ -14,9 +14,6 @@ It provides the following resources:
1414
|------|---------|
1515
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.1.0 |
1616
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.0.0 |
17-
| <a name="requirement_helm"></a> [helm](#requirement\_helm) | >= 2.4.1 |
18-
| <a name="requirement_kubectl"></a> [kubectl](#requirement\_kubectl) | >= 2.0.3 |
19-
| <a name="requirement_kubernetes"></a> [kubernetes](#requirement\_kubernetes) | >= 2.10 |
2017

2118
## Providers
2219

@@ -28,31 +25,32 @@ It provides the following resources:
2825

2926
| Name | Source | Version |
3027
|------|--------|---------|
31-
| <a name="module_helm_addon"></a> [helm\_addon](#module\_helm\_addon) | github.com/aws-ia/terraform-aws-eks-blueprints//modules/kubernetes-addons/helm-addon | v4.32.1 |
28+
| <a name="module_cloudwatch_observability_irsa_role"></a> [cloudwatch\_observability\_irsa\_role](#module\_cloudwatch\_observability\_irsa\_role) | terraform-aws-modules/iam/aws//modules/iam-role-for-service-accounts-eks | v5.33.0 |
3229

3330
## Resources
3431

3532
| Name | Type |
3633
|------|------|
34+
| [aws_eks_addon.amazon_cloudwatch_observability](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/eks_addon) | resource |
35+
| [aws_iam_service_linked_role.application_signals_cw](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_service_linked_role) | resource |
3736
| [aws_caller_identity.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source |
37+
| [aws_eks_addon_version.eks_addon_version](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/eks_addon_version) | data source |
3838
| [aws_eks_cluster.eks_cluster](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/eks_cluster) | data source |
39-
| [aws_iam_policy.irsa](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy) | data source |
4039
| [aws_partition.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/partition) | data source |
4140
| [aws_region.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/region) | data source |
4241

4342
## Inputs
4443

4544
| Name | Description | Type | Default | Required |
4645
|------|-------------|------|---------|:--------:|
47-
| <a name="input_adot_otel_helm_chart_verison"></a> [adot\_otel\_helm\_chart\_verison](#input\_adot\_otel\_helm\_chart\_verison) | ADOT collector helm chart version | `string` | `"0.17.0"` | no |
48-
| <a name="input_eks_cluster_id"></a> [eks\_cluster\_id](#input\_eks\_cluster\_id) | EKS Cluster Id | `string` | n/a | yes |
49-
| <a name="input_helm_config"></a> [helm\_config](#input\_helm\_config) | Helm provider config for adot-exporter-for-eks-on-ec2 | `any` | `{}` | no |
50-
| <a name="input_irsa_iam_permissions_boundary"></a> [irsa\_iam\_permissions\_boundary](#input\_irsa\_iam\_permissions\_boundary) | IAM permissions boundary for IRSA roles | `string` | `null` | no |
51-
| <a name="input_irsa_iam_role_path"></a> [irsa\_iam\_role\_path](#input\_irsa\_iam\_role\_path) | IAM role path for IRSA roles | `string` | `"/"` | no |
52-
| <a name="input_irsa_policies"></a> [irsa\_policies](#input\_irsa\_policies) | Additional IAM policies for a IAM role for service accounts | `list(string)` | `[]` | no |
53-
| <a name="input_manage_via_gitops"></a> [manage\_via\_gitops](#input\_manage\_via\_gitops) | Determines if the add-on should be managed via GitOps. | `bool` | `false` | no |
54-
| <a name="input_service_exporters"></a> [service\_exporters](#input\_service\_exporters) | exporter for adot-ci setup | `string` | `"awsemf"` | no |
55-
| <a name="input_service_receivers"></a> [service\_receivers](#input\_service\_receivers) | receiver for adot-ci setup | `string` | `"awscontainerinsightreceiver"` | no |
46+
| <a name="input_addon_config"></a> [addon\_config](#input\_addon\_config) | Amazon EKS Managed CloudWatch Observability Add-on config | `any` | `{}` | no |
47+
| <a name="input_create_cloudwatch_application_signals_role"></a> [create\_cloudwatch\_application\_signals\_role](#input\_create\_cloudwatch\_application\_signals\_role) | Create a Cloudwatch Application Signals service-linked role | `bool` | `true` | no |
48+
| <a name="input_create_cloudwatch_observability_irsa_role"></a> [create\_cloudwatch\_observability\_irsa\_role](#input\_create\_cloudwatch\_observability\_irsa\_role) | Create a Cloudwatch Observability IRSA | `bool` | `true` | no |
49+
| <a name="input_eks_cluster_id"></a> [eks\_cluster\_id](#input\_eks\_cluster\_id) | Name of the EKS cluster | `string` | `"eks-cw"` | no |
50+
| <a name="input_eks_oidc_provider_arn"></a> [eks\_oidc\_provider\_arn](#input\_eks\_oidc\_provider\_arn) | The OIDC Provider ARN of AWS EKS cluster | `string` | `""` | no |
51+
| <a name="input_enable_amazon_eks_cw_observability"></a> [enable\_amazon\_eks\_cw\_observability](#input\_enable\_amazon\_eks\_cw\_observability) | Enable Amazon EKS CloudWatch Observability add-on | `bool` | `true` | no |
52+
| <a name="input_kubernetes_version"></a> [kubernetes\_version](#input\_kubernetes\_version) | Kubernetes version | `string` | `"1.28"` | no |
53+
| <a name="input_most_recent"></a> [most\_recent](#input\_most\_recent) | Determines if the most recent or default version of the addon should be returned. | `bool` | `false` | no |
5654
| <a name="input_tags"></a> [tags](#input\_tags) | Additional tags (e.g. `map('BusinessUnit`,`XYZ`) | `map(string)` | `{}` | no |
5755

5856
## Outputs
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
data "aws_partition" "current" {}
2+
data "aws_caller_identity" "current" {}
3+
data "aws_region" "current" {}
4+
5+
data "aws_eks_cluster" "eks_cluster" {
6+
name = var.eks_cluster_id
7+
}

0 commit comments

Comments
 (0)