Setting up the CloudWatch agent to collect cluster metrics
Go to IAM Console → Roles.
Click Create role.
Choose Custom trust policy → select EKS cluster nodes.
-
For EC2 worker nodes: choose EC2 as trusted entity.
-
For Fargate: choose EKS Pod Execution Role.
Attach the managed policy: CloudWatchAgentServerPolicy.
Name it EKS-CloudWatchAgent-Role and Create role.
Go to your EKS cluster → Nodes → EC2 instance → IAM role and attach this role.
cd deployments
kubectl create ns amazon-cloudwatch
kubectl apply -f https://raw.githubusercontent.com/aws-samples/amazon-cloudwatch-container-insights/latest/k8s-deployment-manifest-templates/deployment-mode/daemonset/container-insights-monitoring/cwagent/cwagent-serviceaccount.yaml
kubectl apply -f cloudwatch-agent.yamlThis config makes the agent:
- Listen on UDP 8125 for StatsD metrics.
- Push them to CloudWatch every 60 seconds.
- Add useful dimensions (ClusterName, InstanceId).
kubectl apply -f eureka-collector.yaml