Giter Club home page Giter Club logo

amazon-eks-scaling-with-keda-and-karpenter's Introduction

Amazon EKS scaling with KEDA and Karpenter

EKS with KEDA HPA & Karpenter cluster autoscaler

This repository contains the necessary files and instructions to deploy and configure KEDA (Kubernetes-based Event Driven Autoscaling) and Karpenter (Kubernetes Node Autoscaler) on an Amazon Elastic Kubernetes Service (EKS) cluster.

KEDA enables autoscaling of Kubernetes pods based on the number of events in event sources such as Azure Service Bus, RabbitMQ, Kafka, and more. Karpenter is a Kubernetes node autoscaler that scales the number of nodes in your cluster based on resource usage.


Sample Usecase

Full Demo is available @Youtube

Watch the video

Prerequisites

Before you begin, ensure that you have the following prerequisites:

Installation

To install KEDA and Karpenter on your AWS EKS cluster, follow these steps:

  1. Clone this repository to your local machine or download it as a ZIP file.

    git clone https://github.com/aws-samples/amazon-eks-scaling-with-keda-and-karpenter.git
  2. Navigate to the repository's directory.

    cd amazon-eks-scaling-with-keda-and-karpenter
  3. Update environmentVariables.sh file in /deployment

Variable Name Description
AWS_REGION The AWS region.
ACCOUNT_ID The AWS account ID.
TEMPOUT Temporary output file. This used to temp. store CFN for karpenter
DYNAMODB_TABLE The name of the DynamoDB table.
CLUSTER_NAME The name of the EKS cluster.
KARPENTER_VERSION The version of Karpenter.
NAMESPACE The Kubernetes namespace for KEDA.
SERVICE_ACCOUNT The Kubernetes service account for KEDA.
IAM_KEDA_ROLE The IAM role for KEDA.
IAM_KEDA_SQS_POLICY The IAM policy for KEDA to access SQS.
IAM_KEDA_DYNAMO_POLICY The IAM policy for KEDA to access DynamoDB.
SQS_QUEUE_NAME The name of the SQS queue.
SQS_QUEUE_URL The URL of the SQS queue.
SQS_TARGET_DEPLOYMENT The target deployment for KEDA to scale based on SQS messages.
SQS_TARGET_NAMESPACE The target namespace for the deployment that KEDA scales based on SQS messages.
  1. To strat deployment run

    sh ./deployment/_main.sh
  2. You will be asked to verfiy the account in context

  1. Select your deployment option

๐Ÿšจ๐Ÿšจ Experiencing Issues ๐Ÿšจ๐Ÿšจ

If you are experiencing error while deploying Karpenter, it can be due to Karpenter repository currently supports limited version and you may be havign old version in environmentVariables.sh. Please follow steps below:

  • Please check latest karpenter version from https://karpenter.sh -> Getting Started. environmentVariables should match with supported version

  • Check file createkarpenter.sh under deployment-->karpenter line 80 - 90 and compare with karpneter getting started helm https://karpenter.sh/

Mock Testing ๐Ÿ’ป

I have used iTerm2 on Mac with K9s to connect with cluster and run scripts

Architecture

  1. Once Cluster, Karpenter & KEDA is deployed

  1. Open two more terminal and connect to cluster using K9s (check Prerequisites)

  2. In first terminal with K9s, navigate to keda-test namespace pod view

  1. In seconds terminal with k9s, navigate to Nodes

  1. Open three or more terminals, copy content from deployment/environmentVariables.sh and run it on all three terminal

  1. In the terminal run below command to test Karpenter status. If you see error first fix it before moving furthe
kubectl logs -f -n karpenter -l app.kubernetes.io/name=karpenter -c controller

  1. Run keda-mock-sqs-post.py script on all four terminals

    cd app/keda
    python3 -m venv env
    source env/bin/activate
    pip install boto3
    cd  {your path}/amazon-eks-scaling-with-keda-and-karpenter
    python3 ./app/keda/keda-mock-sqs-post.py

  1. Pod sclaing using KEDA

  1. Node scaling using Karpenter

๐Ÿšจ Cleanup ๐Ÿšจ

  1. Navigate to the repository's root directory.

    cd amazon-eks-scaling-with-keda-and-karpenter
  2. To strat cleanup

    sh ./cleanup.sh

This will delelte all the AWS services and workloads created for the solution.

Configuration

The repository contains the necessary configuration files for deploying KEDA and Karpenter. You can modify these files to suit your specific requirements. Here are some important files to note:

Feel free to modify these files according to your needs.

Acknowledgements

  • KEDA - Kubernetes-based Event Driven Autoscaling
  • Karpenter - Kubernetes Node Autoscaler

Security

See CONTRIBUTING for more information.

License

This library is licensed under the MIT-0 License. See the LICENSE file..

amazon-eks-scaling-with-keda-and-karpenter's People

Contributors

amazon-auto avatar khanasif1 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

amazon-eks-scaling-with-keda-and-karpenter's Issues

Cannot run _main.sh on Ubuntu/Debian

$ sh ./deployment/_main.sh
./deployment/_main.sh: 5: source: not found
Please check the details before proceeding
AWS Account:
AWS Region for deployment :

Please check the Karpenter version you have selected is available at

https://karpenter.sh

Also please check #Experiencing Issues# section before proceeding.

Casesenstive Press Y = Proceed or N = Cancel
Response:
Y
./deployment/_main.sh: 13: [[: not found
Cancel deployment

Had to use ap-southeast-2 region

2024-05-03 23:43:22 [โœ–] AWS::EKS::Cluster/ControlPlane: CREATE_FAILED โ€“ย "Resource handler returned message: "Cannot create cluster 'eks-demo-scale' because EKS does not support creating control plane instances in us-east-1e, the targeted availability zone. Retry cluster creation using control plane subnets that span at least two of these availability zones: us-east-1a, us-east-1b, us-east-1c, us-east-1d, us-east-1f. Note, post cluster creation, you can run worker nodes in separate subnets/availability zones from control plane subnets/availability zones passed during cluster creation (Service: Eks, Status Code: 400, Request ID: a03747cf-5348-4112-b69f-81a0028e969c)" (RequestToken: 77039cad-3349-0562-8618-9e2940e909a5, HandlerErrorCode: InvalidRequest)"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.