Using the AWS Cloud Watch agent to publish metrics to CloudWatch in ROSA
This content is authored by Red Hat experts, but has not yet been tested on every supported configuration.
This document shows how you can use the AWS CloudWatch Agent to scrape Prometheus endpoints and publish metrics to CloudWatch in a Red Hat OpenShift Service on AWS (ROSA) cluster.
It pulls from the AWS documentation for installing the CloudWatch Agent to Kubernetes and publishes metrics for the Kubernetes API Server and provides a simple dashboard to view the results.
Currently the AWS CloudWatch Agent does not support pulling all metrics from the Prometheus federated endpoint, but the hope is that when it does we can ship all cluster and user workload metrics to AWS CloudWatch.
Prerequisites
- A Red Hat OpenShift Service on AWS (ROSA) cluster
- The OpenShift CLI (
oc) - The
jqcommand-line interface (CLI) - The Amazon Web Services (AWS) CLI (
aws)
Setting up your environment
Ensure you are logged into your cluster with the OpenShift CLI (
oc) and your AWS account with the AWS CLI (aws).Configure the following environment variables:
Ensure all fields output correctly before moving to the next section:
Preparing your AWS account
Create an IAM role trust policy for the CloudWatch Agent service account to use:
Create an IAM role for the CloudWatch Agent to assume:
Attach the AWS-managed
CloudWatchAgentServerPolicyIAM policy to the IAM role:
Deploy the AWS CloudWatch Agent
Create a project for the AWS CloudWatch Agent:
Create a ConfigMap with the Prometheus CloudWatch Agent config:
Create a ConfigMap for the Prometheus scrape config:
Create a service account for the CloudWatch Agent to use and annotate it with the IAM role we created earlier:
Create a cluster role and role binding for the service account:
Allow the CloudWatch Agent to run with the
anyuidsecurity context constraint:Deploy the CloudWatch Agent pod:
Verify the CloudWatch Agent pod is
Running:Example output
Create Sample Dashboard in AWS CloudWatch
Download the Sample Dashboard
Update the Sample Dashboard
Create a Dashboard, and name it “Kubernetes API Server”
Click Actions and View/edit source
Run the following command and copy the JSON output into the text area:
After 5-10 minutes, view the dashboard and see the data flowing into CloudWatch:
