How to install Cloudwatch in Kubernetes

  1. Search for EKS worker node in AWS IAM
  2. Edit the Worker Node
  3. Assign CloudWatchAgentServerPolicy Policy to that role

Step 1: Create a namespace for 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/cloudwatch-namespace.yaml

Step 2: Create a service account in the cluster

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

Step 3: Create a ConfigMap for the CloudWatch agent

Download the ConfigMap YAML to your kubectl client host by running the following command:

curl -O https://raw.githubusercontent.com/aws-samples/amazon-cloudwatch-container-insights/latest/k8s-deployment-manifest-templates/deployment-mode/daemonset/container-insights-monitoring/cwagent/cwagent-configmap.yaml

Change the Cluster Name

Step 4: Deploy the CloudWatch agent as a DaemonSet

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-daemonset.yaml

Validate that the agent is deployed by running the following command.

kubectl get pods -n amazon-cloudwatch

If the agent doesn’t deploy correctly, try the following:

  • Run the following command to get the list of pods kubectl get pods -n amazon-cloudwatch
  • Run the following command and check the events at the bottom of the output.kubectl describe pod pod-name -n amazon-cloudwatch
  • Run the following command to check the logs.kubectl logs pod-name -n amazon-cloudwatch