A sample JSII construct lib for AWS CDK
npm install cdk-serverless-api


!Release
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.

- [x] support the upstream AWS CDK aws-eks construct libraries by extending its capabilities
- [x] addSpotFleet() to create your spot fleet for your cluster
- [x] define your blockDuration, validFrom and validUntil for fine-graned control
- [x] support any AWS commercial regions which has Amazon EKS and EC2 Spot Block support, including AWS China regions
``ts
import * as eksspot from 'eks-spot-blocks';
import * as cdk from '@aws-cdk/core';
import * as ec2 from '@aws-cdk/aws-ec2';
const clusterStack = new eksspot.EksSpotCluster(stack, 'Cluster', {
clusterVersion: eks.KubernetesVersion.V1_16,
});
clusterStack.addSpotFleet('FirstFleet', {
blockDuration: eksspot.BlockDuration.SIX_HOURS,
targetCapacity: 1,
defaultInstanceType: new ec2.InstanceType('p3.2xlarge'),
validUntil: clusterStack.addHours(new Date(), 6).toISOString(),
terminateInstancesWithExpiration: true
})
clusterStack.addSpotFleet('SecondFleet', {
blockDuration: eksspot.BlockDuration.ONE_HOUR,
targetCapacity: 2,
defaultInstanceType: new ec2.InstanceType('c5.large'),
validUntil: clusterStack.addHours(new Date(), 1).toISOString(),
terminateInstancesWithExpiration: true
})
`
check eks-spot-blocks-demo for a full AWS CDK demo with this construct library.
`ts`
const clusterStack = new EksSpotCluster(stack, 'Cluster', {
clusterVersion: eks.KubernetesVersion.V1_16,
customAmiId: 'ami-xxxxxx'
});
so we can install this library via npm, pypi, maven or nuget.$3
You can block the fleet with hourly increments up to 6 hours.$3
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.$3
Yes. Basically you can configure validFrom, validUntil and terminateInstancesWithExpiration to achieve this. However, consider the following scenario
`
|--------(one hour)-----------------------|<2:00>
|--------(one-hour block)-------|<2:05>
`Your fleet will be terminated at
2:00 rather at 2:05.$3
Yes. (samples TBD)
$3
Yes. Including Beijing(cn-north-1) and Ningxia(cn-northwest-1).$3
According to this document$3
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.