This is quick and dirty MVP which
- loads available EC2 instances
- loads description of all pods in k8s cluster
- calculates cheapest possible placement
Given set of
We also should consider such limitations as:
- we can not overexceed instance capacity by ram or cpu, in other words:
$$\sum_{p=0}^{P} \left( RequirementRam_p * M_p^{i_t} \right) \le AvailableRam_t, \forall i \in \set{0 \dotsc I_t}, \forall t \in \set {0 \dotsc T}$$
- every pod should be placed, and every pod should be placed exactly 1 time:
$$\sum_{i=0}^{I_t} M_p^{i_t} = 1, \forall p \in \set{0 \dotsc P}, \forall t \in \set {0 \dotsc T}$$
We should also specify that instance
Not mandatory for calculation correctness, but is a good relaxation to reduce search area to limit that instances
should be used sequentially (i.e there is no sense to calculate placement for instance
To summarize, our formulation be
Minimize:
Subject to:
AwsInstanceType(name='r6g.medium', ram=8192, cpu=1, price=0.0504) N 4 Total booked capacity 5200.0 ram, 0.9 cpu:
- Pod number 3 DeploymentRequirement(ram=700, cpu=0.2)
- Pod number 4 DeploymentRequirement(ram=500, cpu=0.2)
- Pod number 5 DeploymentRequirement(ram=4000, cpu=0.5)
AwsInstanceType(name='t2.micro', ram=1024, cpu=1, price=0.0162) N 4 Total booked capacity 700.0 ram, 0.5 cpu:
- Pod number 0 DeploymentRequirement(ram=100, cpu=0.1)
- Pod number 1 DeploymentRequirement(ram=100, cpu=0.2)
- Pod number 2 DeploymentRequirement(ram=500, cpu=0.2)