Running containers on spot infrastructure

Michael Wittig – 14 Apr 2021

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.

Reduce your AWS bill

Options

After you select your scheduler EKS or ECS, you can choose from the following options to run your containers on spot:

  • ECS
    • Fargate
    • Self-managed EC2
  • EKS
    • 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!

Fallback to on-demand?

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

Summary

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 :)

Michael Wittig

Michael Wittig

I’ve been building on AWS since 2012 together with my brother Andreas. We are sharing our insights into all things AWS on cloudonaut and have written the book AWS in Action. Besides that, we’re currently working on bucketAV, HyperEnv for GitHub Actions, and marbot.

Here are the contact options for feedback and questions.