Server Migration
After 6 years with the same server in Scaleway, I finally had to migrate to a new machine. This process was way less painful then what I expected, so I thought it could be an interesting write up.
What happened
For some time now I was having problems due to the limited resources of my server (2vCPUs, 2GBs RAM and 50GB storage). I was already had a S3 bucket mounted as a partition to deal with lack of storage and had to constantly restart microblog.pub due to OOM errors.
Last week I decided to update Ubuntu and the server got into a really weird state: I had the latest version of the kernel installed, but it was booting an old version, which lead to some odd behaviors! Apparently the server was always using a bootscript and I was unable to make it use the local configuration. After contacting Scaleway, they mentioned that the instance type was not supported anymore (indeed, this instance type stopped being offered years ago), so the solution would be to update to a newer instance.
Since I had to setup a new server anyway (maybe I could fix the problem with some Linux-fu, but that would be too much work to end up with a server in a weird state), this felt like a good time to try some new things.
Contabo
While I'm pretty happy with Scaleway, their prices have increased quite a bit since I subscribed. I also had this arbitrary goal of keep spending less than 8€/month, just to be able to say that hosting my ActivityPub instance is cheaper than paying for twitter blue .
I recently heard about Contabo on the Scala Discord server. They are based in Germany (I would prefer France like Scaleway, but Germany shouldn't be too bad with regards to latency) and they are surprisingly cheap in comparison - I'm paying ~7€/month for 4vCPU, 8GB RAM and 200GB storage.
Considering the price/specs ratio, I'm expecting some problems down the line and, indeed, my initial impression of the support was quite bad. I believe they currently setup the servers manually and they don't seem to do that on weekends, so it took days from me paying for the server (Saturday) until I got the login details (Tuesday). Also, their management interface is nowhere near as clean as Scaleway's, but that's a minor nitpick.
Still, the server seems to be chugging along just fine, which is the important part. I'll keep it running here for a few more months and then decide if I want to stay here or move somewhere else.
And speaking of moving:
Traefik Proxy
A long time ago a friend showed me his server setup using Traefik Proxy, and I was blown away by it: everything just seemed so clean in nice little configurations (his setup is available in GitHub, if you want to take a look).
As such, I decided to also use Traefik this time (it certainly couldn't be worst than my butchered nginx configs), and I'm pretty happy so far.
My Setup
My current server setup has a directory for each service, where each directory just has:
- a
docker-compose.yml
with the deploy configurations - a
.env
file with sensitive definitions (e.g. credentials) - a
data
directory, to be mounted on the docker container - a
src
directory (for the services where I need to build the image from source)
So, it looks roughly like:
services/ traefik-proxy/ .env data/ docker-compose.yml nginx .env data/ docker-compose.yml microblog .env data/ docker-compose.yml src/ ...
From what I can tell, most people prefer to have a single docker-compose.yml
, but I personally prefer to have everything in separate directories. The only really annoying thing about this so far is to have to manually specify the network on every file, but that's OK for me.
Here's an example of what my Nginx configuration looks like:
version: "3"
services:
server:
image: trafex/php-nginx:latest
container_name: nginx
volumes:
- ./data/html:/var/www/html:ro
restart: unless-stopped
labels:
- "traefik.enable=true"
- "traefik.http.routers.nginx.rule=Host(`joaocosta.eu`, `www.joaocosta.eu`)"
- "traefik.http.routers.nginx.entrypoints=websecure"
- "traefik.http.routers.nginx.tls.certresolver=myresolver"
- "traefik.http.services.nginx-svc.loadbalancer.server.port=8080"
networks:
default:
name: traefik-proxy_default
external: true
Pretty simple and clean, in my opinion. And it automatically takes care of all HTTPS/TLS stuff with Let's Encrypt!
I've seen a lot of example configurations of web that are way more complex, with a ton of middlewares. Maybe I should add those as well, but for now I want to keep everything as simple as possible until I have a better understanding of Traefik's model.
Containers everywhere
While I think in 2023 a lot of developers are already sold on the idea of using containers for everything, I'm sure some people will argue that using containers on a personal server is overkill and that there are better ways to do things that use less resources.
In my previous server I only had containers for a few services and I really don't want to manage non-container services anymore. There are so many small problems with dependencies (I had way too many problems with PHP dependencies in the past) or custom nginx definitions (looking at you Laravel services) that I really don't care to save a few resources anymore.
So, while Traefik does not really require that everything uses Docker (actually, I was surprised by the huge amount of configuration providers), I decided to migrate everything to Docker containers anyway, which also allows me to have a much more uniform Traefik configuration.
Version Control
Another advantage of this new setup is that I can easily manage the configurations via git.
Due to the unified folder structure that I'm using, a simple .gitignore
is enough to make sure that I only keep track of the configurations:
.env data/ src/
Hopefully this will make migrating to another server super easy ! I just need to clone the git repo and scp the remaining files. This also might allow me to rollback changes if I somehow mess up the configuration.
Concluding
Overall, I'm very happy with the current setup. Especially comparing to my old Nginx configuration (which Certbot would always break for some reason), Traefik feels like magic.
And while I'm not sure if Contabo was a good choice or not, having an easy migration plan lets me confidently try out multiple VPS providers if needed.