Cross-compile Containers for ARM

At the time of this writing, X86-64 is the widest spread architecture for Workstations. This may cause us some headache : we can not run the same applications we use on our PCs, into the Raspberry Pi Cluster. We are left with couple options to work around this issue, either build our images on our Pi itself, or, cross-compilation locally. There are quite a few advantages from this setup, speed up the whole process of building, optimize your workflow, keep your babies clean. First thing first, you should have docker already installed on your machine. If you don’t, for debian-based distributions here it is :

sudo apt install docker.io
Docker Buildx is included in Docker 19.03+. It allows us pick up a target architecture for which to build container images for, with a simple flag. Now we need to enable ARM support, install quemu :
sudo apt-get install qemu binfmt-support qemu-user-static
Configure and test :
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
docker run --rm -t arm64v8/ubuntu uname -m
Our environment should be ready to cross-compile, all it needs, is a Dockerfile, with the proper layers. In my case, i needed a php-fpm with several extensions enabled, but there will be many more use cases. Okay, we have built our first container image, now how to deploy on our cluster ? Lucky for us, we‘ve set up a Gitlab instance previosuly on the NAS. Gitlab provides us a container registry, images will be pulled by K3s, and used to deploy your apps.
kubectl create secret docker-registry regcred --docker-server=registry.gitlab.com --docker-username=pervitiner00 --docker-password=changeme123
docker buildx build --platform linux/arm64 -t registry.gitlab.com/username/repository .

Comments

Subscribe to our Newsletter