Skip to main content
Boost your DevOps efficiency! Dive into our latest white paper.Read Now

Run your application on spot instance

Run on spot

Kapstan provides the option to utilize spot instances for Kubernetes workloads, offering potential cost savings for applications that can tolerate interruptions. This feature integrates spot instances with your Kubernetes cluster orchestration.

What are Spot Instances?

Spot instances are spare compute capacity offered at a discounted price compared to on-demand instances. This allow you to run your apps on discounted, interruptible cloud provider instances. This can significantly reduce costs for fault-tolerant workloads while leveraging Kubernetes' scheduling and management capabilities

What are the benefits of enabling spot on Kapstan?

  1. Lower hardware costs: Spot instances can significantly reduce compute expenses, often up to 70-90% compared to on-demand pricing.
  2. Scalability: Easily scale workloads that can handle interruptions.
  3. Automated Management: Kubernetes can handle spot instance interruptions by rescheduling pods.
  4. Resource Optimization: Ideal for batch jobs, stateless applications, stateless applications and dev/test environments.

How to enable Run on Spot in Kapstan?

info

Before enabling the spot instance toggle, ensure your application can gracefully handle potential interruptions. For more information, refer to the best practices for running applications on spot instances.

  1. Navigate to the configuration page for your application (e.g., "api-gateway" in the screenshot).
  2. Select the "Hardware" tab from the left sidebar.
  3. Under the "Hardware" section, locate the "Run on Spot" toggle switch.
  4. Enable the toggle to activate spot instance usage for your workload.
  5. Click the "Save" button to apply the changes and deploy the application.

Best Practices to run applicatons on Spot Instance

Spot Instances offer cost savings by leveraging unused capacity, but their ephemeral nature requires careful application design. Here are best practices to ensure smooth operation when running applications on Spot Instances in a Kubernetes cluster

  1. Stateless Applications: Favor stateless applications, which have no local state and can be easily restarted. This simplifies recovery and avoids data loss when instances are interrupted.

  2. Idempotent Tasks: Ensure tasks can be executed multiple times without unintended consequences. This enables Kubernetes to seamlessly reschedule tasks without introducing errors.

  3. Checkpointing: For long-running tasks, implement checkpointing to save application state periodically using database(persistent storage). This allows the application to resume from the latest checkpoint, minimizing downtime.

  4. Graceful Shutdown: Include a shutdown handler in your container that gracefully terminates the application upon receiving a termination signal(SIGTERM). This involves:

    • Draining Active Connections: Stop accepting new connections and allow existing connections to complete.
    • Flushing Buffers: Flush all data buffers to persistent storage.
    • Saving Application State: Save state to persistent data storage for applications that maintain state.
    • Cleanup Tasks: Perform necessary cleanup tasks, such as releasing resources.
  5. Keep Container Images Small: Optimize container images for size to improve pod launch times and reduce resource consumption. This can involve minimizing dependencies, using multi-stage builds, and compressing image layers. This would help in bringing up pods faster in case of interruptions.

Can't find what you need?