I am using AWS CDK for my Infrastructure-as-Code (CDK code fragments in C# .NET below).
I have a VPC created as follows:
// vpc (testing)
this.vpc = new Vpc(this, "vpc", new VpcProps() {
MaxAzs = 1,
NatGateways = 1
});
I have a cluster created as follows:
// cluster
this.cluster = new Cluster(this, "cluster", new ClusterProps() {
Vpc = this.vpc
});
I have a worker definition for a Fargate Task as follows:
// worker
this.workerDefinition = new FargateTaskDefinition(this,
"worker-definition",
new FargateTaskDefinitionProps() {
Cpu = 256,
MemoryLimitMiB = 512
}
);
I have the Fargate worker service as follows that ties the worker service to the cluster with the instance count and task definition:
var worker = new FargateService(this, "worker", new FargateServiceProps() {
Cluster = this.cluster,
DesiredCount = k, // up to k worker instances
TaskDefinition = this.workerDefinition
});
Questions:
- I want to use k reserved EC2 instances in the cluster as a minimum. Should I create those EC2 instances and add them to the cluster?
- If I call ecs.runTask() using a FARGATE launch type, would the Fargate service be launched on one of the pre-spun EC2 instances until the limit of k is reached (and then, I intend to use an autoscaling rule based on workload to spin up FARGATE_SPOT instances on-demand)?
- Is my understanding that EC2 instances pre-created and added to the cluster will be used to run the FARGATE tasks correct?
- How does the scheduler decide where to place the tasks? Suppose my task is re-entrant (ie., I can run multiple instances on the same machine), how does Fargate know (or how do I instruct it so that it would know) that it can place multiple instances on the same machine (ie., does Fargate automatically use CPU/IO utilization as a metric for packing tasks on a container)?