Set up event-driven auto scaling in Amazon EKS by using Amazon EKS Pod Identity and KEDA
Dipen Desai, Abhay Diwan, Kamal Joshi, and Mahendra Revanasiddappa, Amazon Web Services
Summary
Orchestration platforms, such as Amazon Elastic Kubernetes Service (Amazon EKS), have streamlined the lifecycle management of container-based applications. This helps organizations focus on building, securing, operating, and maintaining container-based applications. As event-driven deployments become more common, organizations are more frequently scaling Kubernetes deployments based on various event sources. This method, combined with auto scaling, can result in significant cost savings by providing on-demand compute resources and efficient scaling that is tailored to application logic.
KEDA
AWS provides AWS Identity and Access Management (IAM) roles that support diverse Kubernetes deployment options, including Amazon EKS, Amazon EKS Anywhere, Red Hat OpenShift Service on AWS (ROSA), and self-managed Kubernetes clusters on Amazon Elastic Compute Cloud (Amazon EC2). These roles use IAM constructs, such as OpenID Connect (OIDC) identity providers and IAM trust policies, to operate across different environments without relying directly on Amazon EKS services or APIs. For more information, see IAM roles for service accounts in the Amazon EKS documentation.
Amazon EKS Pod Identity simplifies the process for Kubernetes service accounts to assume IAM roles without requiring OIDC providers. It provides the ability to manage credentials for your applications. Instead of creating and distributing your AWS credentials to the containers or using the Amazon EC2 instance’s role, you associate an IAM role with a Kubernetes service account and configure your Pods to use the service account. This helps you use an IAM role across multiple clusters and simplifies policy management by enabling the reuse of permission policies across IAM roles.
By implementing KEDA with Amazon EKS Pod Identity, businesses can achieve efficient event-driven auto scaling and simplified credential management. Applications scale based on demand, which optimizes resource utilization and reduces costs.
This pattern helps you integrate Amazon EKS Pod Identity with KEDA. It showcases how you can use the keda-operator
service account and delegate authentication with TriggerAuthentication
. It also describes how to set up a trust relationship between an IAM role for the KEDA operator and an IAM role for the application. This trust relationship allows KEDA to monitor messages in the event queues and adjust scaling for the destination Kubernetes objects.
Prerequisites and limitations
Prerequisites
AWS Command Line Interface (AWS CLI) version 2.13.17 or later, installed
Python version 3.11.5 or later, installed
AWS SDK for Python (Boto3) version 1.34.135 or later, installed
Helm version 3.12.3 or later, installed
kubectl version 1.25.1 or later, installed
Docker Engine version 26.1.1 or later, installed
An Amazon EKS cluster version 1.24 or later, created
Prerequisites for creating the Amazon EKS Pod Identity agent, met
Limitations
It is required that you establish a trust relationship between the
keda-operator
role and thekeda-identity
role. Instructions are provided in the Epics section of this pattern.
Architecture
In this pattern, you create the following AWS resources:
Amazon Elastic Container Registry (Amazon ECR) repository – In this pattern, this repo is named
keda-pod-identity-registry
. This private repo is used to store Docker images of the sample application.Amazon Simple Queue Service (Amazon SQS) queue – In this pattern, this queue is named
event-messages-queue
. The queue acts as a message buffer that collects and stores incoming messages. KEDA monitors the queue metrics, such as message count or queue length, and it automatically scales the application based on these metrics.IAM role for the application – In this pattern, this role is named
keda-identity
. Thekeda-operator
role assumes this role. This role allows access to the Amazon SQS queue.IAM role for the KEDA operator – In this pattern, this role is named
keda-operator
. The KEDA operator uses this role to make the required AWS API calls. This role has permissions to assume thekeda-identity
role. Because of the trust relationship between thekeda-operator
and thekeda-identity
roles, thekeda-operator
role has Amazon SQS permissions.
Through the TriggerAuthentication
and ScaledObject
Kubernetes custom resources, the operator uses the keda-identity
role to connect with an Amazon SQS queue. Based on the queue size, KEDA automatically scales the application deployment. It adds 1 pod for every 5 unread messages in the queue. In the default configuration, if there are no unread messages in the Amazon SQS queue, the application scales down to 0 pods. The KEDA operator monitors the queue at an interval that you specify.
The following image shows how you use Amazon EKS Pod Identity to provide the keda-operator
role with secure access to the Amazon SQS queue.

The diagram shows the following workflow:
You install the Amazon EKS Pod Identity agent in the Amazon EKS cluster.
You deploy KEDA operator in the KEDA namespace in the Amazon EKS cluster.
You create the
keda-operator
andkeda-identity
IAM roles in the target AWS account.You establish a trust relationship between the IAM roles.
You deploy the application in the
security
namespace.The KEDA operator polls messages in an Amazon SQS queue.
KEDA initiates HPA, which automatically scales the application based on the queue size.
Tools
AWS services
Amazon Elastic Container Registry (Amazon ECR) is a managed container image registry service that’s secure, scalable, and reliable.
Amazon Elastic Kubernetes Service (Amazon EKS) helps you run Kubernetes on AWS without needing to install or maintain your own Kubernetes control plane or nodes.
AWS Identity and Access Management (IAM) helps you securely manage access to your AWS resources by controlling who is authenticated and authorized to use them.
Amazon Simple Queue Service (Amazon SQS) provides a secure, durable, and available hosted queue that helps you integrate and decouple distributed software systems and components.
Other tools
KEDA
is a Kubernetes-based event-driven autoscaler.
Code repository
The code for this pattern is available in the GitHub Event-driven auto scaling using EKS Pod Identity and KEDA
Best practices
We recommend that you adhere to the following best practices:
Epics
Task | Description | Skills required |
---|---|---|
Create the IAM role for the KEDA operator. |
| AWS administrator |
Create the IAM role for the sample application. |
| AWS administrator |
Create an Amazon SQS queue. |
| General AWS |
Create an Amazon ECR repository. |
| General AWS |
Task | Description | Skills required |
---|---|---|
Deploy the Amazon EKS Pod Identity agent. | For the target Amazon EKS cluster, set up the Amazon EKS Pod Identity agent. Follow the instructions in Set up the Amazon EKS Pod Identity Agent in the Amazon EKS documentation. | AWS DevOps |
Deploy KEDA. |
| DevOps engineer |
Assign the IAM role to the Kubernetes service account. | Follow the instructions in Assign an IAM role to a Kubernetes service account in the Amazon EKS documentation. Use the following values:
| AWS DevOps |
Create a namespace. | Enter the following command to create a
| DevOps engineer |
Task | Description | Skills required |
---|---|---|
Clone the application files. | Enter the following command to clone the Event-driven auto scaling using EKS Pod Identity and KEDA repository
| DevOps engineer |
Build the Docker image. |
| DevOps engineer |
Push the Docker image to Amazon ECR. |
NoteYou can find push commands by navigating to the Amazon ECR repository page and then choosing View push commands. | DevOps engineer |
Deploy the sample application. |
| DevOps engineer |
Assign the IAM role to the application service account. | Do one of the following to associate the
| DevOps engineer |
Deploy |
| DevOps engineer |
Task | Description | Skills required |
---|---|---|
Send messages to the Amazon SQS queue. |
| DevOps engineer |
Monitor the application pods. |
| DevOps engineer |
Troubleshooting
Issue | Solution |
---|---|
The KEDA operator cannot scale the application. | Enter the following command to check the logs of the
If there is an
If there is an
|
Related resources
Set up the Amazon EKS Pod Identity Agent (Amazon EKS documentation)
Deploying KEDA
(KEDA documentation) ScaledObject specification
(KEDA documentation) Authentication with TriggerAuthentication
(KEDA documentation)