Sub topic 13
Logs and Metrics
This chapter assumes you have a running EKS cluster, can use kubectl and the AWS CLI, and know what IAM roles and CloudWatch are. It covers the two main sources of operational data on EKS: control plane logs and Container Insights metrics.
Two kinds of visibility
EKS splits observability along the same line as responsibility. AWS runs the control plane, so you cannot log in to it. You can ask AWS to send its logs to CloudWatch Logs. You run the data plane, so you collect node and pod data yourself, usually with an agent.
| Layer | What you get | How |
|---|---|---|
| Control plane | API server, audit, authenticator, controller manager and scheduler logs | Enable log types on the cluster |
| Pods and nodes | CPU, memory, network and disk metrics, plus container logs | Install the CloudWatch Observability add-on |
Enabling control plane logs
Control plane logging is off by default. Each log type is switched on separately. Logs go to a CloudWatch log group named /aws/eks/<cluster>/cluster, and you pay CloudWatch ingestion and storage prices for them.
The five log types are api, audit, authenticator, controllerManager and scheduler. The audit log records who called the Kubernetes API and is the most useful for security reviews. The authenticator log shows how IAM identities were mapped to Kubernetes users, which helps when you debug access problems.
aws eks update-cluster-config \
--name demo \
--region us-east-1 \
--logging '{"clusterLogging":[{"types":["api","audit","authenticator"],"enabled":true}]}'You can also set this in an eksctl config with cloudWatch.clusterLogging.enableTypes. The update runs asynchronously. Check progress with aws eks describe-update.
aws logs tail /aws/eks/demo/cluster --follow --region us-east-1Container Insights
CloudWatch Container Insights collects metrics such as pod_cpu_utilization and node_memory_utilization. It groups them by cluster, namespace, service and pod. The recommended way to install it is the Amazon CloudWatch Observability EKS add-on. It deploys the CloudWatch agent and Fluent Bit as DaemonSets, which means one pod runs on every node.
The agent needs permission to write to CloudWatch. Attach the CloudWatchAgentServerPolicy managed policy to a role. Use IRSA or Pod Identity for this, as described in the earlier chapter on pod permissions, rather than the node role.
aws eks create-addon \
--cluster-name demo \
--addon-name amazon-cloudwatch-observability \
--service-account-role-arn arn:aws:iam::111122223333:role/cw-agent-role \
--region us-east-1Common errors
- No data appears after install. Check that the agent pods are running with
kubectl get pods -n amazon-cloudwatch. Then check that the role has the CloudWatch policy. - Fargate pods have no agent data. DaemonSets do not run on Fargate. Use the Fargate built-in log router instead.
- Surprise bills. Audit logs are large on busy clusters. Set a retention period on the log group.
aws logs put-retention-policy \
--log-group-name /aws/eks/demo/cluster \
--retention-in-days 30 \
--region us-east-1Exercise
A teammate enabled the CloudWatch Observability add-on, but no pod metrics show up. The pods in amazon-cloudwatch are running. What is the most likely cause, and where do you look?
Show answer
The agent most likely lacks permission to write to CloudWatch. Check that the role bound to the agent's service account (through IRSA or Pod Identity) has the CloudWatchAgentServerPolicy attached, and read the agent pod logs with kubectl logs for access denied errors.
Exercise
Which log type would you read to find out which IAM identity deleted a Deployment, and how do you turn it on?
Show answer
The audit log. Enable it with aws eks update-cluster-config using a logging configuration that lists "audit" in the types and sets enabled to true. Then read the /aws/eks/<cluster>/cluster log group.