Running containers on spot infrastructure
Running workloads on spot infrastructure is significantly cheaper. You can reduce your bill by 50% or more. Keep in mind that spot workloads can be terminated at any time. If you are lucky, you will be noticed 2 minutes upfront to shut down gracefully. In this blog post, I compare the options that AWS provides to run container workloads on spot infrastructure.
After you select your scheduler EKS or ECS, you can choose from the following options to run your containers on spot:
- Self-managed EC2
- Managed node groups
- Self-managed EC2
Self-managed EC2 benefits from all the spot features that are available for EC2 instances. The downside is the self-managed part: You are responsible for scaling, patching, monitoring, and so on. Therefore, I recommend using the option highlighted in bold. If your scheduler of choice is ECS, I recommend running your workload on Fargate Spot. All you need to do is to turn a single knob. If you prefer EKS, managed node groups are the way to go with native support for spot.
EKS Fargate does not support spot at this time!
How can we fall back to on-demand capacity if the spot capacity was terminated? My usual answer is this: Spot capacity is cheap because AWS can, at any time, decide to take it away from you. If you can not accept that spot capacity can be terminated at any time, it might not be a good fit for your workload!
But wouldn’t it be nice if we could benefit from the spot savings for most of the time but with a safety net of on-demand capacity? If you use ECS, there is no native way of implementing a fallback. If you use EKS, kubernetes and the Autoscaler can do the job. The following video goes into details and includes demos:
- Spot Refresher
- Demo: ECS Fargate
- Pitfall: Handle interruption notice
- Pitfall: Fallback to on-demand
- Demo: EKS managed node group
AWS supports many options to run containers on spot infrastructure to optimize your AWS bill. The clear winners in terms of ease of use are ECS Fargate and EKS managed node groups. I was able to switch from on-demand to spot using ECS Fargate in a couple of minutes. Since then, I enjoy the lower AWS bill :)