Skip to main content

A sample JSII construct lib for AWS CDK

Project description

awscdk-jsii-template NPM version PyPI version Release

cdk-eks-spotblocks

cdk-eks-spotblocks is a JSII construct library for AWS CDK to provison Amazon EKS cluster with EC2 Spot Blocks for defined workloads with the advantages of ensured availability and considerable price reduction for your kubernetes workload.

Features

  • support the upstream AWS CDK aws-eks construct libraries by extending its capabilities
  • addSpotFleet() to create your spot fleet for your cluster
  • define your blockDuration, validFrom and validUntil for fine-graned control
  • support any AWS commercial regions which has Amazon EKS and EC2 Spot Block support, including AWS China regions

Sample

# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
import eks_spot_blocks as eksspot
import aws_cdk.core as cdk
import aws_cdk.aws_ec2 as ec2

cluster_stack = eksspot.EksSpotCluster(stack, "Cluster",
    cluster_version=eks.KubernetesVersion.V1_16
)

cluster_stack.add_spot_fleet("FirstFleet",
    block_duration=eksspot.BlockDuration.SIX_HOURS,
    target_capacity=1,
    default_instance_type=ec2.InstanceType("p3.2xlarge"),
    valid_until=cluster_stack.add_hours(Date(), 6).to_iSOString(),
    terminate_instances_with_expiration=True
)

cluster_stack.add_spot_fleet("SecondFleet",
    block_duration=eksspot.BlockDuration.ONE_HOUR,
    target_capacity=2,
    default_instance_type=ec2.InstanceType("c5.large"),
    valid_until=cluster_stack.add_hours(Date(), 1).to_iSOString(),
    terminate_instances_with_expiration=True
)

check eks-spot-blocks-demo for a full AWS CDK demo with this construct library.

Custom AMI support

# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
cluster_stack = EksSpotCluster(stack, "Cluster",
    cluster_version=eks.KubernetesVersion.V1_16,
    custom_ami_id="ami-xxxxxx"
)

FAQ

Does eks-spot-blocks support existing eks clusters created by eksctl, terraform or any other tools?

No. This construct library does not support existing Amazon EKS clusters. You have to create the cluster as well as the spot fleet altogether in this construct library.

Can I write the CDK in other languages like Python and Java?

Not at this moment. But we plan to publish this construct with JSII so we can install this library via npm, pypi, maven or nuget.

How much time can I block the spotfleet?

You can block the fleet with hourly increments up to 6 hours.

What happens after the blockDuration?

Spot Blocks ensure the availability of your spot instances during the blockDuration and avoid termination during the price disruption. After the blockDuration, by default, your spot instances will still be in running state but it doesn't ensure the availability, which means it might be terminated anytime after the blockDuration.

Can I terminate the fleet immediately after the blockDuration to save the money?

Yes. Basically you can configure validFrom, validUntil and terminateInstancesWithExpiration to achieve this.

However, consider the following scenario

<deploy start at 1:00>|--------(one hour)-----------------------|<2:00>
                           |<fleet created at 1:05>--------(one-hour block)-------|<2:05>

Your fleet will be terminated at 2:00 rather at 2:05.

Are tains and labels supported?

Yes.

(samples TBD)

Does it support AWS China regions?

Yes. Including Beijing(cn-north-1) and Ningxia(cn-northwest-1).

How much can I save from the EC2 Spot Block compared to the on-demand?

According to this document

Spot Instances are also available to run for a predefined duration – in hourly increments up to six hours in length – at a discount of up to 30-50% compared to On-Demand pricing.

Will this library become part of the upstream aws-eks construct library?

Probably. As it's still in the preliminary stage, we are still collecting feedbacks from the community to make eks-spot-blocks ready for production workloads. Eventually we will commit this feature to the upstream aws-eks construct library in AWS CDK through pull requests.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

eks-spot-blocks-0.2.53.tar.gz (43.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

eks_spot_blocks-0.2.53-py3-none-any.whl (41.8 kB view details)

Uploaded Python 3

File details

Details for the file eks-spot-blocks-0.2.53.tar.gz.

File metadata

  • Download URL: eks-spot-blocks-0.2.53.tar.gz
  • Upload date:
  • Size: 43.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.7.9

File hashes

Hashes for eks-spot-blocks-0.2.53.tar.gz
Algorithm Hash digest
SHA256 1523f4710fae66c4a4f6335891d7ec168abbf22a781b13ccf81749c352ceabe1
MD5 7505ffdf4ca7a52c36595cbb1e2ef162
BLAKE2b-256 8a353d0cdf4c85c2776bec7c1c7c2fdbf52ab022de8416c66acf3d9d2ecf209a

See more details on using hashes here.

File details

Details for the file eks_spot_blocks-0.2.53-py3-none-any.whl.

File metadata

  • Download URL: eks_spot_blocks-0.2.53-py3-none-any.whl
  • Upload date:
  • Size: 41.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.7.9

File hashes

Hashes for eks_spot_blocks-0.2.53-py3-none-any.whl
Algorithm Hash digest
SHA256 492c74d04d2a69c57547635c2b94c512eee79a66fdd4812c39aec9432f3151f0
MD5 2fbce7e63b612fd7bdbce8acbbdbcf89
BLAKE2b-256 ba89d3c7c3a1b42fcc47f47fa2b5e2d2c093ccc6c8dc1fec2dd784ba680e15ba

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page