|
| 1 | +# Existing Cluster with the AWS Observability accelerator base module and Nginx monitoring |
| 2 | + |
| 3 | + |
| 4 | +This example demonstrates how to use the AWS Observability Accelerator Terraform |
| 5 | +modules with Nginx monitoring enabled. |
| 6 | +The current example deploys the [AWS Distro for OpenTelemetry Operator](https://docs.aws.amazon.com/eks/latest/userguide/opentelemetry.html) for Amazon EKS with its requirements and make use of existing |
| 7 | +Amazon Managed Service for Prometheus and Amazon Managed Grafana workspaces. |
| 8 | + |
| 9 | +It is based on the `nginx module`, one of our [workload modules](../../modules/workloads/) |
| 10 | +to provide an existing EKS cluster with an OpenTelemetry collector, |
| 11 | +curated Grafana dashboards, Prometheus alerting and recording rules with multiple |
| 12 | +configuration options on the cluster infrastructure. |
| 13 | + |
| 14 | + |
| 15 | +## Prerequisites |
| 16 | + |
| 17 | +Ensure that you have the following tools installed locally: |
| 18 | + |
| 19 | +1. [aws cli](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html) |
| 20 | +2. [kubectl](https://kubernetes.io/docs/tasks/tools/) |
| 21 | +3. [terraform](https://learn.hashicorp.com/tutorials/terraform/install-cli) |
| 22 | + |
| 23 | + |
| 24 | +## Setup |
| 25 | + |
| 26 | +This example uses a local terraform state. If you need states to be saved remotely, |
| 27 | +on Amazon S3 for example, visit the [terraform remote states](https://www.terraform.io/language/state/remote) documentation |
| 28 | + |
| 29 | +1. Clone the repo using the command below |
| 30 | + |
| 31 | +``` |
| 32 | +git clone https://github.com/aws-observability/terraform-aws-observability-accelerator.git |
| 33 | +``` |
| 34 | + |
| 35 | +2. Initialize terraform |
| 36 | + |
| 37 | +```console |
| 38 | +cd examples/existing-cluster-nginx |
| 39 | +terraform init |
| 40 | +``` |
| 41 | + |
| 42 | +3. AWS Region |
| 43 | + |
| 44 | +Specify the AWS Region where the resources will be deployed. Edit the `terraform.tfvars` file and modify `aws_region="..."`. You can also use environement variables `export TF_VAR_aws_region=xxx`. |
| 45 | + |
| 46 | +4. Amazon EKS Cluster |
| 47 | + |
| 48 | +To run this example, you need to provide your EKS cluster name. |
| 49 | +If you don't have a cluster ready, visit [this example](https://github.com/aws-ia/terraform-aws-eks-blueprints/tree/main/examples/eks-cluster-with-new-vpc) |
| 50 | +first to create a new one. |
| 51 | + |
| 52 | +Add your cluster name for `eks_cluster_id="..."` to the `terraform.tfvars` or use an environment variable `export TF_VAR_eks_cluster_id=xxx`. |
| 53 | + |
| 54 | +5. Amazon Managed Service for Prometheus workspace (optional) |
| 55 | + |
| 56 | +If you have an existing workspace, add `managed_prometheus_workspace_id=ws-xxx` |
| 57 | +or use an environment variable `export TF_VAR_managed_prometheus_workspace_id=ws-xxx`. |
| 58 | + |
| 59 | +If you don't specify anything a new workspace will be created for you. |
| 60 | + |
| 61 | +6. Amazon Managed Grafana workspace |
| 62 | + |
| 63 | +If you have an existing workspace, add `managed_grafana_workspace_id=g-xxx` |
| 64 | +or use an environment variable `export TF_VAR_managed_grafana_workspace_id=g-xxx`. |
| 65 | + |
| 66 | +7. Grafana API Key |
| 67 | + |
| 68 | +- Give admin access to the SSO user you set up when creating the Amazon Managed Grafana Workspace: |
| 69 | +- In the AWS Console, navigate to Amazon Grafana. In the left navigation bar, click **All workspaces**, then click on the workspace name you are using for this example. |
| 70 | +- Under **Authentication** within **AWS Single Sign-On (SSO)**, click **Configure users and user groups** |
| 71 | +- Check the box next to the SSO user you created and click **Make admin** |
| 72 | +- From the workspace in the AWS console, click on the `Grafana workspace URL` to open the workspace |
| 73 | +- If you don't see the gear icon in the left navigation bar, log out and log back in. |
| 74 | +- Click on the gear icon, then click on the **API keys** tab. |
| 75 | +- Click **Add API key**, fill in the _Key name_ field and select _Admin_ as the Role. |
| 76 | +- Copy your API key into `terraform.tfvars` under the `grafana_api_key` variable (`grafana_api_key="xxx"`) or set as an environment variable on your CLI (`export TF_VAR_grafana_api_key="xxx"`) |
| 77 | + |
| 78 | + |
| 79 | +## Deploy |
| 80 | + |
| 81 | +```sh |
| 82 | +terraform apply -var-file=terraform.tfvars |
| 83 | +``` |
| 84 | + |
| 85 | +or if you had setup environment variables, run |
| 86 | + |
| 87 | +```sh |
| 88 | +terraform apply |
| 89 | +``` |
| 90 | + |
| 91 | +## Visualization |
| 92 | + |
| 93 | +1. Prometheus datasource on Grafana |
| 94 | + |
| 95 | +Open your Grafana workspace and under Configuration -> Data sources, you should see `aws-observability-accelerator`. Open and click `Save & test`. You should see a notification confirming that the Amazon Managed Service for Prometheus workspace is ready to be used on Grafana. |
| 96 | + |
| 97 | +2. Grafana dashboards |
| 98 | + |
| 99 | +Go to the Dashboards panel of your Grafana workspace. You should see a list of dashboards under the `Observability Accelerator Dashboards` |
| 100 | + |
| 101 | +<img width="1208" alt="image" src="https://user-images.githubusercontent.com/97046295/190665211-60faef71-d83d-4d59-ac80-bf4309d8c082.png"> |
| 102 | + |
| 103 | +Open the NGINX dashboard and you should be able to view its visualization |
| 104 | + |
| 105 | +<img width="895" alt="image" src="https://user-images.githubusercontent.com/97046295/190665477-6660a6cf-3b29-4209-8387-6d4fc61aca5a.png"> |
| 106 | + |
| 107 | +2. Amazon Managed Service for Prometheus rules and alerts |
| 108 | + |
| 109 | +Open the Amazon Managed Service for Prometheus console and view the details of your workspace. Under the `Rules management` tab, you should find new rules deployed. |
| 110 | + |
| 111 | +<img width="1054" alt="image" src="https://user-images.githubusercontent.com/97046295/190665728-ae8bb709-ad93-4629-b845-85c158dd1925.png"> |
| 112 | + |
| 113 | + |
| 114 | +To setup your alert receiver, with Amazon SNS, follow [this documentation](https://docs.aws.amazon.com/prometheus/latest/userguide/AMP-alertmanager-receiver.html) |
| 115 | + |
| 116 | +## Deploy an Example Application to Visualize |
| 117 | + |
| 118 | +In this section we will deploy sample application and extract metrics using AWS OpenTelemetry collector |
| 119 | + |
| 120 | +1. Add the helm incubator repo: |
| 121 | + |
| 122 | +```sh |
| 123 | +helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx |
| 124 | +``` |
| 125 | + |
| 126 | +2. Enter the following command to create a new namespace: |
| 127 | + |
| 128 | +```sh |
| 129 | +kubectl create namespace nginx-ingress-sample |
| 130 | +``` |
| 131 | + |
| 132 | +3. Enter the following commands to install NGINX: |
| 133 | + |
| 134 | +```sh |
| 135 | +helm install my-nginx ingress-nginx/ingress-nginx \ |
| 136 | +--namespace nginx-ingress-sample \ |
| 137 | +--set controller.metrics.enabled=true \ |
| 138 | +--set-string controller.metrics.service.annotations."prometheus\.io/port"="10254" \ |
| 139 | +--set-string controller.metrics.service.annotations."prometheus\.io/scrape"="true" |
| 140 | +``` |
| 141 | + |
| 142 | +4. Set an EXTERNAL-IP variable to the value of the EXTERNAL-IP column in the row of the NGINX ingress controller. |
| 143 | + |
| 144 | +```sh |
| 145 | +EXTERNAL_IP=your-nginx-controller-external-ip |
| 146 | +``` |
| 147 | + |
| 148 | +5. Start some sample NGINX traffic by entering the following command. |
| 149 | + |
| 150 | +```sh |
| 151 | +SAMPLE_TRAFFIC_NAMESPACE=nginx-sample-traffic |
| 152 | +curl https://raw.githubusercontent.com/aws-samples/amazon-cloudwatch-container-insights/master/k8s-deployment-manifest-templates/deployment-mode/service/cwagent-prometheus/sample_traffic/nginx-traffic/nginx-traffic-sample.yaml | |
| 153 | +sed "s/{{external_ip}}/$EXTERNAL_IP/g" | |
| 154 | +sed "s/{{namespace}}/$SAMPLE_TRAFFIC_NAMESPACE/g" | |
| 155 | +kubectl apply -f - |
| 156 | +``` |
| 157 | + |
| 158 | +4. Verify if the application is running |
| 159 | + |
| 160 | +```sh |
| 161 | +kubectl get pods -n nginx-ingress-sample |
| 162 | +``` |
| 163 | + |
| 164 | +#### Visualize the Application's dashboard |
| 165 | + |
| 166 | +Log back into your Managed Grafana Workspace and navigate to the dashboard side panel, click on `Observability Accelerator Dashboards` Folder and open the `NGINX` Dashboard. |
| 167 | + |
| 168 | +## Destroy |
| 169 | + |
| 170 | +To teardown and remove the resources created in this example: |
| 171 | + |
| 172 | +```sh |
| 173 | +terraform destroy |
| 174 | +``` |
| 175 | + |
| 176 | +## Advanced configuration |
| 177 | + |
| 178 | +1. Cross-region Amazon Managed Prometheus workspace |
| 179 | + |
| 180 | +If your existing Amazon Managed Prometheus workspace is in another AWS Region, |
| 181 | +add this `managed_prometheus_region=xxx` and `managed_prometheus_workspace_id=ws-xxx`. |
| 182 | + |
| 183 | +2. Cross-region Amazon Managed Grafana workspace |
| 184 | + |
| 185 | +If your existing Amazon Managed Prometheus workspace is in another AWS Region, |
| 186 | +add this `managed_prometheus_region=xxx` and `managed_prometheus_workspace_id=ws-xxx`. |
| 187 | + |
| 188 | + |
| 189 | +<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK --> |
| 190 | +## Requirements |
| 191 | + |
| 192 | +| Name | Version | |
| 193 | +|------|---------| |
| 194 | +| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0.0 | |
| 195 | +| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.0.0 | |
| 196 | +| <a name="requirement_grafana"></a> [grafana](#requirement\_grafana) | >= 1.25.0 | |
| 197 | +| <a name="requirement_grafana"></a> [grafana](#requirement\_grafana) | >= 1.25.0 | |
| 198 | +| <a name="requirement_helm"></a> [helm](#requirement\_helm) | >= 2.4.1 | |
| 199 | +| <a name="requirement_kubectl"></a> [kubectl](#requirement\_kubectl) | >= 1.14 | |
| 200 | +| <a name="requirement_kubernetes"></a> [kubernetes](#requirement\_kubernetes) | >= 2.10 | |
| 201 | + |
| 202 | +## Providers |
| 203 | + |
| 204 | +| Name | Version | |
| 205 | +|------|---------| |
| 206 | +| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.0.0 | |
| 207 | + |
| 208 | +## Modules |
| 209 | + |
| 210 | +| Name | Source | Version | |
| 211 | +|------|--------|---------| |
| 212 | +| <a name="module_eks_observability_accelerator"></a> [eks\_observability\_accelerator](#module\_eks\_observability\_accelerator) | ../../ | n/a | |
| 213 | +| <a name="module_workloads_nginx"></a> [workloads\_nginx](#module\_workloads\_nginx) | ../../modules/workloads/nginx | n/a | |
| 214 | + |
| 215 | +## Resources |
| 216 | + |
| 217 | +| Name | Type | |
| 218 | +|------|------| |
| 219 | +| [aws_eks_cluster.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/eks_cluster) | data source | |
| 220 | +| [aws_eks_cluster_auth.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/eks_cluster_auth) | data source | |
| 221 | + |
| 222 | +## Inputs |
| 223 | + |
| 224 | +| Name | Description | Type | Default | Required | |
| 225 | +|------|-------------|------|---------|:--------:| |
| 226 | +| <a name="input_aws_region"></a> [aws\_region](#input\_aws\_region) | AWS Region | `string` | n/a | yes | |
| 227 | +| <a name="input_eks_cluster_id"></a> [eks\_cluster\_id](#input\_eks\_cluster\_id) | Name of the EKS cluster | `string` | n/a | yes | |
| 228 | +| <a name="input_grafana_api_key"></a> [grafana\_api\_key](#input\_grafana\_api\_key) | API key for authorizing the Grafana provider to make changes to Amazon Managed Grafana | `string` | `""` | no | |
| 229 | +| <a name="input_managed_grafana_workspace_id"></a> [managed\_grafana\_workspace\_id](#input\_managed\_grafana\_workspace\_id) | Amazon Managed Grafana Workspace ID | `string` | `""` | no | |
| 230 | +| <a name="input_managed_prometheus_workspace_id"></a> [managed\_prometheus\_workspace\_id](#input\_managed\_prometheus\_workspace\_id) | Amazon Managed Service for Prometheus Workspace ID | `string` | `""` | no | |
| 231 | + |
| 232 | +## Outputs |
| 233 | + |
| 234 | +| Name | Description | |
| 235 | +|------|-------------| |
| 236 | +| <a name="output_aws_region"></a> [aws\_region](#output\_aws\_region) | AWS Region | |
| 237 | +| <a name="output_eks_cluster_id"></a> [eks\_cluster\_id](#output\_eks\_cluster\_id) | EKS Cluster Id | |
| 238 | +| <a name="output_eks_cluster_version"></a> [eks\_cluster\_version](#output\_eks\_cluster\_version) | EKS Cluster version | |
| 239 | +| <a name="output_managed_prometheus_workspace_endpoint"></a> [managed\_prometheus\_workspace\_endpoint](#output\_managed\_prometheus\_workspace\_endpoint) | Amazon Managed Prometheus workspace endpoint | |
| 240 | +| <a name="output_managed_prometheus_workspace_id"></a> [managed\_prometheus\_workspace\_id](#output\_managed\_prometheus\_workspace\_id) | Amazon Managed Prometheus workspace ID | |
| 241 | +<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK --> |
0 commit comments