Create spot capacity
Lets deploy a managed node group that creates Spot instances, followed by modifying the existing catalog
component of our application to run on the newly created Spot instances.
We can get started by listing all of the nodes in our existing EKS cluster. The kubectl get nodes
command can be used to list the nodes in your Kubernetes cluster, but to get additional detail about the capacity type, we'll use the -L eks.amazonaws.com/capacityType
parameter.
The following command shows that our nodes are currently on-demand instances.
NAME STATUS ROLES AGE VERSION CAPACITYTYPE
ip-10-42-103-103.us-east-2.compute.internal Ready <none> 133m v1.31-eks-036c24b ON_DEMAND
ip-10-42-142-197.us-east-2.compute.internal Ready <none> 133m v1.31-eks-036c24b ON_DEMAND
ip-10-42-161-44.us-east-2.compute.internal Ready <none> 133m v1.31-eks-036c24b ON_DEMAND
If you want to retrieve nodes based on a specific capacity type, such as on-demand
instances, you can utilize "label selectors". In this particular scenario, you can achieve this by setting the label selector to capacityType=ON_DEMAND
.
NAME STATUS ROLES AGE VERSION
ip-10-42-10-119.us-east-2.compute.internal Ready <none> 3d10h v1.31-eks-036c24b
ip-10-42-10-200.us-east-2.compute.internal Ready <none> 3d10h v1.31-eks-036c24b
ip-10-42-11-94.us-east-2.compute.internal Ready <none> 3d10h v1.31-eks-036c24b
ip-10-42-12-235.us-east-2.compute.internal Ready <none> 4h34m v1.31-eks-036c24b
In the below diagram, there are two separate "node groups" representing the managed node groups within the cluster. The first Node Group box represents the node group containing On-Demand instances while the second represents the node group containing Spot instances. Both are associated with the specified EKS cluster.
Let's create a node group with Spot instances. The following command creates a new node group managed-spot
.
The --capacity-type SPOT
argument indicates that all capacity in this managed node group should be Spot.
The aws eks wait nodegroup-active
command can be used to wait until a specific EKS node group is active and ready for use. This command is part of the AWS CLI and can be used to ensure that the specified node group has been successfully created and all the associated instances are running and ready.
Once our new managed node group is Active, run the following command.
NAME STATUS ROLES AGE VERSION CAPACITYTYPE NODEGROUP
ip-10-42-103-103.us-east-2.compute.internal Ready <none> 3h38m v1.31-eks-036c24b ON_DEMAND default
ip-10-42-142-197.us-east-2.compute.internal Ready <none> 3h38m v1.31-eks-036c24b ON_DEMAND default
ip-10-42-161-44.us-east-2.compute.internal Ready <none> 3h38m v1.31-eks-036c24b ON_DEMAND default
ip-10-42-178-46.us-east-2.compute.internal Ready <none> 103s v1.31-eks-036c24b SPOT managed-spot
ip-10-42-97-19.us-east-2.compute.internal Ready <none> 104s v1.31-eks-036c24b SPOT managed-spot
The output shows that two additional nodes got provisioned under the node group managed-spot
with capacity type as SPOT
.