Using LXD's Instance Types to Emulate Public Clouds (Amazon, Google, or Azure) Specification

One of the challenges when developing using public clouds provides like Amazon, Google, or Azure is how do we emulate, to the closest specification of their cloud instance locally? LXD, the system container, does have a feature, where you can specify the instance-types during container creation. The public cloud specification is based on the mapping done by the instance type project. While this is not a full emulation of the actual public cloud environment, it's just the essential resource allocations like CPU, memory, disk size, or others. Nevertheless, it's a good and quick way to bootstrap your container to roughly match the resource allocated of these public cloud offering.

Before that, please check the available CPU cores and memory your machine have. In my lappy, we have 4 CPU cores and 7G of memory.
$ nproc && free -g
              total        used        free      shared  buff/cache   available
Mem:              7           6           0           0           1           0
Swap:             0           0           0

How does instance types works in LXD? Let's us create a container based on AWS t2.micro which have the specification of 1 CPU and 1 Gb RAM. All commands are equivalent but using different syntax.
$ lxc launch ubuntu:18.04 c1 -t aws:t2.micro # <cloud>:<instance type>
$ lxc launch ubuntu:18.04 c2 -t t2.micro # <instance type>
$ lxc launch ubuntu:18.04 c3 -t c1-m1 # c<CPU>-m<RAM in GB>

Check our specification of our created containers.
$ lxc config show c1 | grep -E "cpu|memory"
  limits.cpu: "1"
  limits.memory: 1024MB

Again, alternative way to get the config details of the container.
$ lxc config get c1 limits.cpu
$ lxc config get c1 limits.memory

No comments:

Post a Comment