Skip to content

Commit 062b933

Browse files
committed
OSDOCS-7789: Mobb Migration
1 parent ec226ae commit 062b933

File tree

3 files changed

+185
-4
lines changed

3 files changed

+185
-4
lines changed

_images/dashboard.png

158 KB
Loading

_topic_maps/_topic_map_rosa.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,12 @@ Topics:
7878
# - Name: Training for ROSA
7979
# File: rosa-training
8080
#---
81-
#Name: Tutorials
82-
#Dir: rosa_tutorials
83-
#Distros: openshift-rosa
84-
#Topics:
81+
Name: Tutorials
82+
Dir: rosa_tutorials
83+
Distros: openshift-rosa
84+
Topics:
85+
- Name: Using the AWS CloudWatch agent to publish metrics to CloudWatch in ROSA
86+
File: rosa-mobb-aws-cloudwatch-publish-metrics
8587
---
8688
Name: Getting started
8789
Dir: rosa_getting_started
Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
:_content-type: ASSEMBLY
2+
[id="rosa-mobb-aws-cloudwatch-publish-metrics"]
3+
= Tutorial: Using the AWS CloudWatch agent to publish metrics to CloudWatch in ROSA
4+
include::_attributes/attributes-openshift-dedicated.adoc[]
5+
:context: rosa-mobb-aws-cloudwatch-publish-metrics
6+
7+
toc::[]
8+
9+
//Mobb content metadata
10+
//Brought into ROSA product docs 2023-09-19
11+
//---
12+
//date: '2021-10-04'
13+
//title: Using the AWS Cloud Watch agent to publish metrics to CloudWatch in ROSA
14+
//tags: ["AWS", "ROSA"]
15+
//authors:
16+
// - Kevin Collins
17+
//---
18+
19+
include::snippets/mobb-support-statement.adoc[leveloffset=+1]
20+
21+
You can use the AWS CloudWatch agent to scrape Prometheus endpoints and publish metrics to CloudWatch in a {product-title} (ROSA) cluster.
22+
23+
It pulls from The AWS documentation for installing the CloudWatch agent to Kubernetes and collections and publishes metrics for the Kubernetes API Server and provides a simple Dashboard to view the results.
24+
25+
[Important]
26+
====
27+
The AWS CloudWatch Agent does link:https://github.com/aws/amazon-cloudwatch-agent/issues/187[not support] pulling all metrics from the Prometheus federated endpoint.
28+
====
29+
30+
.Prerequisites
31+
32+
* The link:https://aws.amazon.com/cli/[AWS CLI]
33+
* The link:https://stedolan.github.io/jq/[`jq` command]
34+
* A ROSA cluster
35+
36+
== Preparing your AWS account
37+
. Turn off AWS CLI paging:
38+
+
39+
[source,terminal]
40+
----
41+
export AWS_PAGER=""
42+
----
43+
44+
. Set the environment variables:
45+
+
46+
Change the values to suit your environment.
47+
+
48+
[source,terminal]
49+
----
50+
export CLUSTER_NAME=metrics
51+
export CLUSTER_REGION=us-east-2
52+
export SCRATCH_DIR=/tmp/scratch
53+
mkdir -p $SCRATCH_DIR
54+
----
55+
56+
. Create an AWS IAM user for CloudWatch:
57+
+
58+
[source,terminal]
59+
----
60+
aws iam create-user \
61+
--user-name $CLUSTER_NAME-cloud-watch \
62+
> $SCRATCH_DIR/aws-user.json
63+
----
64+
65+
. Fetch access and secret keys for the IAM user:
66+
+
67+
[source,terminal]
68+
----
69+
aws iam create-access-key \
70+
--user-name $CLUSTER_NAME-cloud-watch \
71+
> $SCRATCH_DIR/aws-access-key.json
72+
----
73+
74+
. Attach a policy to AWS IAM user:
75+
+
76+
[source,terminal]
77+
----
78+
aws iam attach-user-policy \
79+
--user-name $CLUSTER_NAME-cloud-watch \
80+
--policy-arn "arn:aws:iam::aws:policy/CloudWatchAgentServerPolicy"
81+
----
82+
83+
== Deploying the CloudWatch Prometheus agent
84+
85+
. Create a namespace for CloudWatch:
86+
+
87+
[source,terminal]
88+
----
89+
oc create namespace amazon-cloudwatch
90+
----
91+
92+
. Download the CloudWatch agent Kubernetes manifests:
93+
+
94+
[source,terminal]
95+
----
96+
wget -O $SCRATCH_DIR/cloud-watch.yaml https://mobb.ninja/docs/rosa/metrics-to-cloudwatch-agent/cloud-watch.yaml
97+
----
98+
99+
. Update the CloudWatch agent Kubernetes manifests:
100+
+
101+
[source,terminal]
102+
----
103+
sed -i .bak "s/__cluster_name__/$CLUSTER_NAME/g" $SCRATCH_DIR/cloud-watch.yaml
104+
sed -i .bak "s/__cluster_region__/$CLUSTER_REGION/g" $SCRATCH_DIR/cloud-watch.yaml
105+
----
106+
107+
. Provide AWS credentials to the CloudWatch agent:
108+
+
109+
[source,terminal]
110+
----
111+
AWS_ID=`cat $SCRATCH_DIR/aws-access-key.json | jq -r '.AccessKey.AccessKeyId'`
112+
AWS_KEY=`cat $SCRATCH_DIR/aws-access-key.json | jq -r '.AccessKey.SecretAccessKey'`
113+
114+
echo "[AmazonCloudWatchAgent]\naws_access_key_id = $AWS_ID\naws_secret_access_key = $AWS_KEY" \
115+
> $SCRATCH_DIR/credentials
116+
117+
oc --namespace amazon-cloudwatch \
118+
create secret generic aws-credentials \
119+
--from-file=credentials=$SCRATCH_DIR/credentials
120+
----
121+
122+
. Allow the CloudWatch agent to run as a root user inside the container:
123+
+
124+
[source,terminal]
125+
----
126+
oc -n amazon-cloudwatch adm policy \
127+
add-scc-to-user anyuid -z cwagent-prometheus
128+
----
129+
130+
. Apply the CloudWatch agent Kubernetes manifests:
131+
+
132+
[source,terminal]
133+
----
134+
oc apply -f $SCRATCH_DIR/cloud-watch.yaml
135+
----
136+
137+
. Check that the pod is running:
138+
+
139+
[source,terminal]
140+
----
141+
oc get pods -n amazon-cloudwatch
142+
----
143+
+
144+
You should see:
145+
+
146+
[source,terminal]
147+
----
148+
NAME READY STATUS RESTARTS AGE
149+
cwagent-prometheus-54cd498c9c-btmjm 1/1 Running 0 60m
150+
----
151+
152+
== Creating a sample dashboard
153+
154+
. Download the sample dashboard:
155+
+
156+
[source,terminal]
157+
----
158+
wget -O $SCRATCH_DIR/dashboard.json https://raw.githubusercontent.com/rh-mobb/documentation/main/content/docs/rosa/metrics-to-cloudwatch-agent/dashboard.json
159+
----
160+
161+
. Update the sample dashboard:
162+
+
163+
[source,terminal]
164+
----
165+
sed -i .bak "s/__CLUSTER_NAME__/$CLUSTER_NAME/g" $SCRATCH_DIR/dashboard.json
166+
sed -i .bak "s/__REGION_NAME__/$CLUSTER_REGION/g" $SCRATCH_DIR/dashboard.json
167+
----
168+
169+
. Go to the link:https://us-east-2.console.aws.amazon.com/cloudwatch[CloudWatch section] of the AWS Console.
170+
171+
. Create a dashboard and name it "Kubernetes API Server".
172+
173+
. Select *Actions*, then *View/edit source*.
174+
175+
. Paste the JSON contents from `$SCRATCH_DIR/dashboard.json` into the text area.
176+
177+
. View the dashboard:
178+
+
179+
image::dashboard.png[]

0 commit comments

Comments
 (0)