Configure Log Collection, Target, and Visualization - AWS
Note!
You need to have a proper EKS cluster setup in order to proceed with these steps. Refer to Set Up Kubernetes Cluster - AWS (4.3)ย to create the EKS cluster first.
To get a production ready log configuration you can use tools from the Kubernetes ecosystem and AWS CloudWatch. In this guide we show you how to set up:
Fluent-bit for log collection and log forwarding
Elasticsearch for log storage
Kibana for log visualization
AWS CloudWatch for monitoring
These tools give you powerful and flexible log collection, storage, monitoring and visualization. The Elasticsearch database storage also provides powerful tools to perform analytics on the log data. The AWS CloudWatch is a monitoring service built for DevOps engineers, developers, site reliability engineers (SREs), IT managers, and product owners. See the official user documentation for detailed information about these tools.
Prerequisite
Setup AWS IAM OIDC Provider
To use AWS Identity and Access Management (IAM) roles for service accounts, an IAM OIDC provider must exist for your cluster's OIDC issuer URL.ย Prior to creating AWS policy and role, you need to setup Identity Provider using EKS cluster's OpenID Connect Provider URL.
Login to AWS Management Console, go to EKS > Clusters > Your Cluster Name.
On Overview tab, section Details, click on the copy button underย OpenID Connect Provider URL to copy the URL to the clipboard.
AWS Console - Overview tabGo to IAM > Identity Providers.
Add an Identity Provider and select OpenID Connect.
Paste the copied URL as Provider URL.
Enter "sts.amazonaws.com" as Audience.
Click Add Provider and proceed to complete the Identity Providers creationย
Setup AWS IAM Policy and Role
In order for Fluent-bit to send logs to AWS CloudWatch, you need to setup AWS access policy to access the AWS CloudWatch and attach this policy to an AWS Role.ย
Login to AWS Management Console, go to IAM > Policies.
Create a new policy using the JSON tab in the Policy Editor. Enter the permission statement in JSON format, as below:
{ "Version": "2012-10-17", "Statement": [ { "Action": [ "logs:DescribeLogGroups", "logs:DescribeLogStreams", "logs:CreateLogGroup", "logs:CreateLogStream", "logs:PutLogEvents" ], "Resource": "*", "Effect": "Allow" } ] }
Click Next and proceed to create the policy.
Back in the IAM Dashboard, go to IAM > Roles.
Create a new role and select Web Identity.
Select the OpenID Connect Provider Id as Identity Provider.
Click Next and proceed to create the role.
Once the new role has been created, you need to to edit the role's trust relationship to associate it to the Fluent-bit's Service Account.
Go to IAM > Roles > Your Role Name.
On the Trust relationship tab, edit trust policy.
Edit the "StringEquals" field to use the Fluent-bit's namespace and Service Account Name, as below:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "Federated": "arn:aws:iam::211006581866:oidc-provider/oidc.eks.ap-southeast-2.amazonaws.com/id/360F8C7227656FC5627D5DA70F181583" }, "Action": "sts:AssumeRoleWithWebIdentity", "Condition": { "StringEquals": { "oidc.eks.ap-southeast-2.amazonaws.com/id/360F8C7227656FC5627D5DA70F181583:sub": "system:serviceaccount:<Fluent-bit namespace>:<fluent-bit Service Account Name>" } } } ] }
Install Fluent-bit
To stream container logs to CloudWatch Logs, install AWS for Fluent-bit:
Create a namespace called amazon-cloudwatch with the following command:
kubectl create namespace amazon-cloudwatch
Create a ConfigMap called fluent-bit-cluster-info and replace my-cluster-name and my-cluster-region with your cluster's name and Region, as below:
Deploy the Fluent-bit DaemonSet to the cluster with the following command:
Associate the IAM role to cloudwatch-agent and fluent-bit service accounts and replaceย ACCOUNT_IDย andย IAM_ROLE_NAMEย with AWS Account ID and the IAM role used for service accounts with the following command:
Go to CloudWatch > View logs and verify that the following log groups have been created:
For each log group, verify there are log streams available in the Log stream tab.
Log streams
Install Elastic Search
Elastic search will be installed to the same namespace as Fluent-bit, i.e.,ย amazon-cloudwatch.ย
Add Elastic Search repository to Helm and update repository to retrieve the latest version with the following commands:
Install Elastic Search.ย
Example - Installing Elasticsearch without Persistent storage
This example installs Elasticsearch without persistent storage. Refer to Elasticsearch Helm chart documentation for help to enable persistent storage:
Install Kibana
Kibanaย will be installed in the same namespace as Fluent-bit, that isย amazon-cloudwatch.ย
Download the Kibana helm chart and unpack it in local directory with the following command:
Change directory to kibana and edit the values.yaml file by adding service annotation to create an Internet-facing, Network type Load Balancer, as below:
Install Kibana by path to an unpacked local directory with the following command:
Configure Fluent-bit to send logs to Elastic Searchย
These are additional steps to configure fluent-bit ConfigMap namedย fluent-bit-config.
Get the service name of the Elastic Search pods with the following command:
This service name is the value set to Host in [OUTPUT] directive.ย
Getย username and password credential for Elastic X-Pack access. with the following commands:
The decrypted username and password are the values set to HTTP_User andย HTTP_Passwdย in [OUTPUT] directive.
Download the fluent-bit deamonset yaml file into a local directory with the following command:
Edit the fluent-bit.yaml file by going to the ConfigMap namedย fluent-bit-config, and for each config file, add the output directive to send logs to Elastic Search, as below:
application-log.conf
dataplane-log.conf
host-log.conf
Delete the existing fluent-bit pods, config map with the following command:
Install and apply the new configuration to fluent-bit pods, config mapย with the following command:ย
Re-associate the IAM role with the cloudwatch-agent and fluent-bit service accounts, and replaceย ACCOUNT_IDย andย IAM_ROLE_NAMEย with AWS Account ID and the IAM role used for service accounts with the following command:
Verify every Fluent-bit pod's log with the following command:
You should not see any error or exception if connection to Elastic Search is established successfully.
Configure Kibana
Kibana is a visual interface tool that allows you to explore, visualize, and build a dashboard over the log data massed in Elastic Search cluster.ย
Up to this stage, all pods under namespaceย amazon-cloudwatch should be up and running.ย
If all looks good, you can proceed to login to Kibana dashboard web UI.
Retrieve the public access hostname of the Kibana dashboard.
Login to Kibana dashboard web UI with username password same asย HTTP_User andย HTTP_Passwd configured in previous section
Go to Management > Stack Management > Index Management. Create the Index Template withย Index Pattern matching the indexes configured in previous section
If Fluent-bit connection to Elastic Search established successfully, the Indices is created automatically.
Go to Management > Stack Management > Kibana. Create Data view matching the index pattern.
Go to Analytics > Discover to search for logs belong to each index pattern respectively.ย
User can filter logs using KQL syntax. For instance, enter "kubernetes.pod_name:platform-0" in the KQL filter input field.
Log record in json format is parsed into fields.