czyykj.com

AWS EKS Workshop: Mastering Managed Node Groups with Spot Instances

Written on

Introduction

Spot Instances utilize spare EC2 capacity available at a lower rate than On-Demand pricing. Leveraging these instances can significantly reduce overall Amazon EC2 operational expenses for workloads that can tolerate interruptions.

See the savings illustrated below:

In this chapter, we will engage in a hands-on approach to provisioning, managing, and maintaining EC2 Spot Capacity using Amazon EKS Managed Node Groups.

Best Practices for EC2 Spot Instances

  1. Suitable Workloads: Spot Instances are ideal for stateless, fault-tolerant applications, working effectively in scenarios such as big data, containerized workloads, CI/CD, stateless web services, high-performance computing (HPC), and rendering tasks.
  2. Unsuitable Workloads: They are not recommended for workloads that are inflexible, stateful, or fault-intolerant, particularly those that cannot handle occasional unavailability of the desired capacity.

To successfully adopt Spot Instances, consider implementing Spot Instance Diversification. This strategy involves sourcing capacity from various Spot Instance pools for scaling and replacing instances when a termination notice is received.

In the context of Amazon EKS, common strategies for diversifying Spot Instance pools include:

  1. Creating multiple node groups of varying sizes (e.g., one group with 4 vCPUs and 16GB RAM, another with 8 vCPUs and 32GB RAM).
  2. Implementing instance diversification within node groups by selecting a variety of instance types and families from different Spot Instance pools that meet the same vCPU and memory requirements.

For this demonstration, we will focus on instance types with 2 vCPUs and 4GiB of memory. The command-line tool amazon-ec2-instance-selector will assist in identifying the relevant instance types and families.

This complete end-to-end demonstration will follow these steps:

  1. Create an Amazon EKS cluster with a standard ON_DEMAND Node Group.
  2. Establish a second Node Group for Spot Capacity to run our selected workloads.
  3. Modify our demo retail application's Catalog component to operate on Spot instances in the second node group.
  4. Simulate Spot Interruption to observe how the EKS Node Group manages interruptions seamlessly, replacing nodes without disrupting the application (see command output post-implementation).

Managed Node Groups (MNG) with Spot Instances — Theory and References

  1. Managed Node Groups (MNG) with Spot Instances EKS Workshop Page — This is the primary source for this post, providing comprehensive conceptual guidance and hands-on steps.
  2. Amazon EKS Managed Spot Workers Workshop — Another workshop focused on Spot Computing within the Amazon EKS environment.
  3. Amazon EC2 Instance Purchasing Options Documentation — Essential reading for understanding On-Demand, Spot, and other computing options available on AWS.
  4. Amazon EC2 Instance Selector — GitHub repository and guide for this useful command-line tool.
  5. Spot Instance Interruptions — A practical simulation of Spot Instance termination and its handling within the Amazon EKS architecture.
  6. Tutorial: Test Spot Instance Interruptions Using AWS FIS — Learn to simulate Spot interruptions with the Fault Injection Service.
  7. AWS Blog: Amazon EKS and Spot Instances in Action at Delivery Hero — Similar hands-on experience shared by the Delivery Hero team.
  8. AWS Blog: Building for Cost Optimization and Resilience for EKS with Spot Instances — An introductory blog with additional insights.

Managed Node Groups (MNG) with Spot Instances — Hands-On Implementation

It's time to build!

We begin from scratch with access to an AWS account. The upcoming steps will guide you through the process. First, follow the instructions from previous chapters to create the cluster, then proceed with preparing the environment.

The end-to-end demonstration consists of FIVE STEPS:

  1. Build Cluster and Prepare Environment
  2. Instance Type Diversification
  3. Create Spot Capacity
  4. Run a Workload on Spot
  5. Simulate Spot Interruption with AWS FIS

Step 1: Build Cluster and Prepare Environment

Ensure you have created an Amazon EKS Cluster as instructed in EKS Workshop Chapter 2.

Prepare the environment for MNG - Spot Instances:

prepare-environment fundamentals/mng/spot

Step 2: Instance Type Diversification

Provision the second node group with instance types having 2 vCPUs and 4GiB of memory. Use the amazon-ec2-instance-selector tool to identify the relevant instance types.

Verify that the CLI tool is operational:

ec2-instance-selector --version

Use the tool to list instances:

ec2-instance-selector --vcpus 2 --memory 4 --gpus 0 --current-generation -a x86_64 --deny-list 't.*' --output table-wide

Step 3: Create Spot Capacity

Deploy a managed node group dedicated to Spot instances. Name this group 'managed-spot'.

aws eks create-nodegroup

--cluster-name $EKS_CLUSTER_NAME

—nodegroup-name managed-spot

--node-role $SPOT_NODE_ROLE

—subnets $PRIMARY_SUBNET_1 $PRIMARY_SUBNET_2 $PRIMARY_SUBNET_3

--instance-types m5.large t3.medium t3.large

—capacity-type SPOT

--scaling-config minSize=2,maxSize=3,desiredSize=2

—disk-size 20

Step 4: Run a Workload on Spot

Adjust the retail store application to run the catalog component on the new Spot instances by adding a nodeSelector field.

Review and apply the Kustomize patch:

kubectl apply -k ~/environment/eks-workshop/modules/fundamentals/mng/spot/deployment

Step 5: Simulate Spot Interruption with AWS FIS

To create a simulation of a Spot interruption, download the FIS template:

wget https://raw.githubusercontent.com/build-on-aws/run-kubernetes-clusters-for-less-with-amazon-ec2-spot-and-karpenter/main/fis/spotinterruption.yaml

Deploy the FIS template with CloudFormation:

aws cloudformation deploy

--stack-name fis-spot

—template-file spotinterruption.yaml

--capabilities "CAPABILITY_NAMED_IAM"

Spot Node Interruption Handling by Spot Node Group — Screenshot

Conclusion and Next Steps

This chapter offered a comprehensive, hands-on demonstration of using the amazon-ec2-instance-selector tool, provisioning and managing EC2 Spot Capacity within an Amazon EKS cluster, and effectively handling Spot interruptions while adhering to Kubernetes best practices.

It is advisable to explore the integration of scalable, resilient system designs that leverage the cost-saving potential of Spot instances, rather than solely depending on pricier On-Demand instances. This chapter serves as a solid foundation for those looking to adopt such strategies in both non-containerized and container-based environments like Amazon EKS.

With Chapter 34— Managed Node Groups (MNG) for EC2 Spot Capacity/Instances, we conclude the Managed Node Groups section of the Amazon EKS Fundamentals module. Our next focus will be on implementing Amazon EKS Fargate.

See you there soon!

> If you found this article helpful, please share it to assist others; your support is greatly appreciated!

Share the page:

Twitter Facebook Reddit LinkIn

-----------------------

Recent Post:

The Truth Behind Baby Formula Marketing: What Parents Should Know

Discover the dubious claims of baby formula marketing and what the science really says about infant nutrition.

# Understanding and Easing the Burden of the Ego

Explore how to detach from your ego and foster peace through self-awareness and acceptance.

Unlocking Financial Wisdom: Insights from an Overlooked Book

Discover profound insights on money management and financial freedom from Morgan Housel's lesser-known book.

The Truth Behind Sports Supplements: Are They Worth It?

A closer look at sports supplements reveals many are ineffective and poorly regulated, leading to consumer deception.

Feeling Small: Finding Comfort in Our Cosmic Perspective

Discover how embracing our smallness in the universe can lead to a more peaceful and compassionate life.

The Unexpected Costliest Catastrophe in Australia's History

Discover how a hailstorm became the most expensive disaster in Australia, surpassing floods and fires.

Unlocking the Potential of MongoDB for Startups and Beyond

Discover how MongoDB can empower startups with its robust support and technology, fostering a culture of innovation and growth.

Unmasking Deception: Why Recognizing Lies Can Be Challenging

Discover why spotting lies is tough and learn practical tips to enhance your skills in detecting deception.