Package: eks-spot-blocks
cdk-eks-spotblockscdk-eks-spotblocksis a JSII construct library for AWS CDK to provison Amazon EKS cluster withEC2 Spot Blocksfor defined workloads with the advantages of ensured availability and considerable price reduction for your kubernetes workload.Featuressupport the upstream AWS CDKaws-eksconstruct libraries by extending its capabilitiesaddSpotFleet()to create your spot fleet for your clusterdefine yourblockDuration,validFromandvalidUntilfor fine-graned controlsupport any AWS commercial regions which has Amazon EKS and EC2 Spot Block support, including AWS China regionsSampleimport*aseksspotfrom'eks-spot-blocks';import*ascdkfrom'@aws-cdk/core';import*asec2from'@aws-cdk/aws-ec2';constclusterStack=neweksspot.EksSpotCluster(stack,'Cluster',{clusterVersion:eks.KubernetesVersion.V1_16,});clusterStack.addSpotFleet('FirstFleet',{blockDuration:eksspot.BlockDuration.SIX_HOURS,targetCapacity:1,defaultInstanceType:newec2.InstanceType('p3.2xlarge'),validUntil:clusterStack.addHours(newDate(),6).toISOString(),terminateInstancesWithExpiration:true})clusterStack.addSpotFleet('SecondFleet',{blockDuration:eksspot.BlockDuration.ONE_HOUR,targetCapacity:2,defaultInstanceType:newec2.InstanceType('c5.large'),validUntil:clusterStack.addHours(newDate(),1).toISOString(),terminateInstancesWithExpiration:true})checkeks-spot-blocks-demofor a full AWS CDK demo with this construct library.Custom AMI supportconstclusterStack=newEksSpotCluster(stack,'Cluster',{clusterVersion:eks.KubernetesVersion.V1_16,customAmiId:'ami-xxxxxx'});FAQDoeseks-spot-blockssupport existing eks clusters created byeksctl,terraformor 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 likePythonandJava?Not at this moment. But we plan to publish this construct withJSIIso we can install this library vianpm,pypi,mavenornuget.How much time can I block the spotfleet?You can block the fleet with hourly increments up to 6 hours.What happens after theblockDuration?Spot Blocks ensure the availability of your spot instances during theblockDurationand avoid termination during the price disruption. After theblockDuration, by default, your spot instances will still be inrunningstate but it doesn't ensure the availability, which means it might be terminated anytime after theblockDuration.Can I terminate the fleet immediately after theblockDurationto save the money?Yes. Basically you can configurevalidFrom,validUntilandterminateInstancesWithExpirationto 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 at2:00rather at2:05.Aretainsandlabelssupported?Yes.(samples TBD)Does it support AWS China regions?Yes. IncludingBeijing(cn-north-1) andNingxia(cn-northwest-1).How much can I save from the EC2 Spot Block compared to the on-demand?According to thisdocumentSpot 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 upstreamaws-eksconstruct library?Probably. As it's still in the preliminary stage, we are still collecting feedbacks from the community to makeeks-spot-blocksready for production workloads. Eventually we will commit this feature to the upstreamaws-eksconstruct library in AWS CDK through pull requests.