30. 10. 2023 Lorenzo Candeago DevOps

LVM Disks on Azure for Dockerized Applications

As an example of a Logical Volume Manager ( LVM ) setup on Azure, let me show you a real-world use case. Say we want to run a Pulp 3 container to host an rpm repo on Azure. As the base image let’s choose Rocky Linux 9.

The machine that we provision will have two extra hard drives, one for the Docker overlay and one for the Pulp 3 repo data. Thanks to LVM, if in the future the repo needs to grow, we can simply add a disk and resize the volume group.

The first problem that we encounter is that Rocky’s default rpm mirrors are too slow to install even a single package: to overcome this issue it’s enough to add fastestmirror=True to /etc/dnf/dnf.conf and run dnf update.

To use LVM we need to install the lvm2 rpm:

sudo dnf install lvm2

For our setup we’ll use the disks sdc and sdd for our lvm volumes.

lsblk -o NAME,HCTL,SIZE,MOUNTPOINT | grep -i "sd"
sda    0:0:0:0      10G 
├─sda1             100M /boot/efi
├─sda2            1000M /boot
├─sda3             7.8G /
├─sda4               4M 
└─sda5               1M 
sdb    0:0:0:1       8G 
└─sdb1               8G /mnt
sdc    1:0:0:0      32G 
sdd    1:0:0:1      64G 

First let’s create the physical volumes:

sudo pvcreate /dev/sdc
sudo pvcreate /dev/sdd

And then create the volume groups:

vgcreate docker_overlay_vg /dev/sdc
vgcreate pulp3_vg /dev/sdd

Now let’s create logical volumes and set them to use all the available space on their respective volume groups:

lvcreate -l +100%free -n docker_overalay_lv docker_overlay_vg
lvcreate -l +100%free -n pulp3_lv pulp3_vg

Finally, we can create the file systems on the logical volumes, in our case we choose xfs:

mkfs.xfs /dev/docker_overlay_vg/docker_overlay_lv 
mkfs.xfs /dev/pulp3_vg/pulp3_lv 

The last step is to mount the newly created volumes to the correct location and add them to fstabs. I’ll just show the procedure for one volume, since it’s the same for both.

First, let’s create the mount point for the Docker storage location and get the UID of the Docker logical volume:

mkdir /var/lib/docker
blkid | grep overlay 
/dev/mapper/docker_overlay_vg-docker_overlay_lv: UUID="46c7eb1e-5b10-4f17-9d7b-d59995574ffb" TYPE="xfs"

Next, let’s append the mount point using the uid to /etc/fstabs:

UUID=46c7eb1e-5b10-4f17-9d7b-d59995574ffb  /var/lib/docker     defaults        0 0 

and finally reboot. Now we see:

 df -h
Filesystem                                       Size  Used Avail Use% Mounted on
[..]
/dev/mapper/docker_overlay_vg-docker_overlay_lv   32G  261M   32G   1% /var/lib/docker
[..]

More advanced solutions for Docker storage and LVM, such as using LVM thin provisioning, could be used but are outside of the scope of this blog post.

These Solutions are Engineered by Humans

Did you find this article interesting? Does it match your skill set? Our customers often present us with problems that need customized solutions. In fact, we’re currently hiring for roles just like this and others here at Würth Phoenix.

Lorenzo Candeago

Lorenzo Candeago

DevOps Engineer at Würth Phoenix

Author

Lorenzo Candeago

DevOps Engineer at Würth Phoenix

Leave a Reply

Your email address will not be published. Required fields are marked *

Archive