How to use spot instances during the Christmas frenzy?
Tags: cloud, kubernetes, tutorial, devops
Published: 2021-12-17 09:26:32

<!-- wp:paragraph -->
<p>You’ve been doing a great job using spot instances for the entire year. But as 2021 is coming to a close, you might have noticed that there’s less inventory of your favorite instance types.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>And even when you manage to get your hands on some, <strong>they get reclaimed rather quickly</strong>. Everyone else needs extra capacity during the holiday season.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><strong>Can you even trust spot instances to reduce your costs at such a critical time?</strong> Should you run everything on on-demand instances and pay the premium just to keep the application running?&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Those are the questions we will answer in this article.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Jump to the section that’s most relevant to you:</p>
<!-- /wp:paragraph -->

<!-- wp:list -->
<ul><li><a href="#dealingwithspotinstanceinterruptions">Dealing with spot instance interruptions manually is hard</a></li><li><a href="#andwhatifyouhandledspotinstancesautomatically">And what if you handled the spot interruptions automatically?</a></li><li><a href="#automationtakesmanytasksoffyourplate">Automation takes many tasks off your plate</a></li><li><a href="#hereshowspotinstanceautomationworks">Here’s how spot instance automation works in practice</a></li><li><a href="#theresultsmaysurpriseyou">The results may surprise you</a></li></ul>
<!-- /wp:list -->

<!-- wp:heading -->
<h2 id="dealingwithspotinstanceinterruptions">Dealing with spot instance interruptions manually is hard</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Hyperscalers like AWS, Google Cloud, and Azure have massive data centers scattered around the globe. At some point, they find themselves with spare capacity and they offer it at a discounted price.</p>
<!-- /wp:paragraph -->

<!-- wp:quote {"className":"is-style-large"} -->
<blockquote class="wp-block-quote is-style-large"><p>The only catch is that the vendor can pull the plug at any time. This makes spot instances generally difficult to manage for production workloads. When getting a spot instance, you have no guarantee on how long it will stay available.&nbsp;&nbsp;</p></blockquote>
<!-- /wp:quote -->

<!-- wp:paragraph -->
<p>Vendors only share some historical data about past interruptions to help you make a more informed decision. Or notify you when the risk of interruption increases for the instance you’re using to give you some extra time.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>A spot instance is reclaimed with short notice - from 2 minutes to as little as 30 seconds. <strong>Is that enough time to drop everything and find a replacement for your instance?&nbsp;</strong>You may know a superhuman engineer who’s able to do that, but they surely have more productive tasks to do.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><strong>Spinning up a new instance takes time&nbsp;</strong></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>And even if you identify the virtual machine where to move your workload, creating a new one takes time, so you’re still facing the danger of potential downtime.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><strong>Running paused machines means extra costs</strong></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Alternatively, you could have some paused machines at your disposal that could step in if you happen to lose a spot instance. But this comes at an additional price, and aren’t you in the spot business to save on your cloud costs?&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><strong>Spot instance availability changes rapidly</strong></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Another issue is that the available capacity sold as spot instances can differ a lot based on size, region, time of day, and many other factors - all subject to frequent changes.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>The availability of an instance is based on supply and demand. So if you pick the most popular instance types and a market surge like Black Friday occurs, prepare for a nasty surprise.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2 id="andwhatifyouhandledspotinstancesautomatically">And what if you handled the spot interruptions automatically?</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Using an automation platform addresses all the problems listed above and makes all the difference when it comes to your cloud bill. You can rely on spot instances even during the most intense times of the year.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>At CAST AI, we have the <strong>Spot Fallback feature that keeps your workloads running even if the cloud provider sells all the capacity and there are no spot instances left for you to use</strong>. If no spot instances matching your requirements are available, the autoscaler temporarily adds an on-demand node for your spot-only workloads so they have a place to run on.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Once the inventory of Spot/Preemptible instances is available again, the autoscaler replaces the on-demand nodes used during the fallback with actual spot instances.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>That way you can still get the benefits of spot instances without having to be anxious about the potential downtime.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p></p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":4759,"sizeSlug":"full","linkDestination":"none"} -->
<figure class="wp-block-image size-full"><img src="https://cast.ai/wp-content/uploads/2021/12/Spot-Fallback-GIF.gif" alt="spot instances" class="wp-image-4759"/></figure>
<!-- /wp:image -->

<!-- wp:heading -->
<h2 id="automationtakesmanytasksoffyourplate">Automation takes many tasks off your plate</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>But arguably the best part is that you don’t need to care about provisioning instances. Moving a workload from one spot instance to another is challenging if you do it manually because it’s a multi-step process:</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><strong>1. Examine the cloud provider offer</strong></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>You can check the less popular instances - they're less likely to be interrupted and can run for longer periods of time. Before deciding to buy an instance, look at how often it is interrupted (its interruption or eviction rate).</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><strong>2. Make your bid</strong></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Set the maximum price you want to spend for your preferred spot instance. The rule of thumb is to follow the level of on-demand pricing and avoid getting interrupted when the price of that instance spikes.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><strong>3. Manage spot instances in groups</strong></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>This opens the doors to request a variety of instance types at the same time and increases your chances of securing a spot instance. You can get more tips about managing spot instances here: <a href="https://cast.ai/blog/how-to-reduce-cloud-costs-by-90-spot-instances-and-how-to-use-them/" target="_blank" rel="noreferrer noopener">Spot instances: How to reduce AWS, Azure, and GCP costs by 90%</a></p>
<!-- /wp:paragraph -->

<!-- wp:quote {"className":"is-style-large"} -->
<blockquote class="wp-block-quote is-style-large"><p>To make spot instances work and secure the right mix of instances, you’ll have to dedicate a lot of time and effort to configuration, setup, and maintenance.</p></blockquote>
<!-- /wp:quote -->

<!-- wp:paragraph -->
<p>A good automation platform will do them all for you. All you need to do is set up the right policies and see your workloads gracefully moved from one instance to another when interruption happens. Here’s how.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2 id="hereshowspotinstanceautomationworks">Here’s how spot instance automation works in practice&nbsp;</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>CAST AI is an automation platform that uses a mix of tactics to optimize cloud costs and help teams get the performance they need. This approach extends to how spot instances are automated in CAST AI.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>The platform doesn’t stick to a predefined list of instance types, but instead scans workloads for spot suitability and matches their requirements automatically. You can edit the list of spot-suitable workloads afterwards.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>This flow is a lot faster than selecting the instance types you prefer manually and picking the pods which shouldn’t run on spot instances at all. The AI checks it all for you in minutes.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:quote {"className":"is-style-large"} -->
<blockquote class="wp-block-quote is-style-large"><p>During the times when everyone is competing for spot instances they know and use, you will be playing in a mostly empty playground of ALL instance types suitable for your application.</p></blockquote>
<!-- /wp:quote -->

<!-- wp:heading {"level":3} -->
<h3>Configuring the automation</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>You can automate spot instances on Kubernetes workloads running on EKS, Kops, AKS, and GKE. Here’s a short overview of how you can configure CAST AI to cover all the scenarios your application might face.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><strong>Tolerations</strong></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>This configuration comes in handy when spot instances are an optional choice for your workload.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>When your pod is marked only with tolerations, the Kubernetes scheduler can place the pod on both spot and regular nodes, always picking the most cost-effective resources.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><strong>Node Selectors</strong></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>In this configuration, workloads will only use spot instances. The autoscaling mechanism will pick a spot instance whenever your pod requires an additional workload in the cluster.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><strong>Node Affinity</strong></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Here we use spot instances if they’re available - if not, the application falls back to on-demand instances.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>For example, if a spot instance gets interrupted and the on-demand instances in the cluster have some available capacity, pods that previously ran on that spot instance will be scheduled on the available on-demand resources. Moving your workloads back to spot instances is possible via the Rebalancer feature.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><strong>Spot Reliability</strong></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>This configuration focuses on minimizing the chance of workload interruptions. The autoscaler identifies which instance types are less likely to be interrupted and you can set a default reliability value to be applied across the entire cluster.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>The reliability value is measured by the percentage of reclaimed instances during the trailing month for this instance type. Click <a href="https://docs.cast.ai/guides/spot/#tolerations">here</a> for more info.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>You can control the reliability value at a more granular level, per workload. For example, you can leave the most cost-efficient value globally and choose more stable instances for specific workloads.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2 id="theresultsmaysurpriseyou">The results may surprise you</h2>
<!-- /wp:heading -->

<!-- wp:image {"id":4760,"sizeSlug":"full","linkDestination":"none"} -->
<figure class="wp-block-image size-full"><img src="https://cast.ai/wp-content/uploads/2021/12/Optimize-CAST-AI.png" alt="" class="wp-image-4760"/></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>A few months ago, we decided to check whether we were really using the best instances available and were shocked to see this spot instance recommendation: the INF1 instance. Who would CAST AI pick that for us? It's essentially a supercomputer for high-performance ML inference that costs a lot if you buy it for on-demand pricing.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Funnily enough, the CAST AI platform didn’t go off rails. The INF1 spot instance was actually cheaper at that point in time than the typical instance we were getting.</p>
<!-- /wp:paragraph -->

<!-- wp:quote {"className":"is-style-large"} -->
<blockquote class="wp-block-quote is-style-large"><p>So while everyone was manually competing for what they knew, we rented a Ferrari for the price of a Fiat just because automation looked at every single instance type that can do the job.</p></blockquote>
<!-- /wp:quote -->

<!-- wp:paragraph -->
<p>If we were choosing instances manually, we’d never look into this category. Automation expanded our reach and got us this gem of an instance.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>If you are ready to quit competing on the same level everyone’s on - let us know and we’ll happily show you around the CAST AI platform.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p id="wisepops-demo-bar-email"></p>
<!-- /wp:paragraph -->