Running Flatcar Container Linux on Hetzner | Flatcar Container Linux
Running Flatcar Container Linux on Hetzner
Hetzner Cloud
is a cloud hosting provider.
Flatcar Container Linux is not installable as one of the default operating system options, but you can deploy it by installing it through the rescue OS.
These instructions require Flatcar with version 3941.1.0 or newer.
Creating snapshots
Snapshots in Hetzner Cloud can be used as a base image to create new servers from. While you can manually create the snapshot, this guide will demonstrate two tools to prepare the snapshots for you.
exportHCLOUD_TOKEN=<your-token>
packer init .
# This will build the snapshot for x86 (amd64-usr) and Arm (arm64-usr).packer build .
The packer build . command takes a few minutes to complete. Afterward you can see the snapshot names and IDs:
1
2
3
==> Builds finished. The artifacts of successful builds are:
--> hcloud.x86: A snapshot was created: 'flatcar-beta-x86'(ID: 157132241)--> hcloud.arm: A snapshot was created: 'flatcar-beta-arm'(ID: 157132242)
You can verify these through the hcloud CLI:
1
2
3
4
$ hcloud image list --type=snapshot --selector=os=flatcar
ID TYPE NAME DESCRIPTION ARCHITECTURE IMAGE SIZE
167650172 snapshot - flatcar-beta-arm arm 0.41 GB
167650577 snapshot - flatcar-beta-x86 x86 0.47 GB
exportHCLOUD_TOKEN=<your-token>
exportCHANNEL=beta
# "current" is the latest version, you can specify alternative version here (e.g 3941.1.0)exportVERSION=current
# For x86 (cx, cpx & ccx Server Types)hcloud-upload-image upload \
--architecture=x86 \
--compression=bz2 \
--image-url=https://${CHANNEL}.release.flatcar-linux.net/amd64-usr/${VERSION}/flatcar_production_hetzner_image.bin.bz2 \
--labels os=flatcar,flatcar-channel=${CHANNEL}\
--description flatcar-${CHANNEL}-x86
# For Arm (cax Server Types)hcloud-upload-image upload \
--architecture=arm \
--compression=bz2 \
--image-url=https://${CHANNEL}.release.flatcar-linux.net/arm64-usr/${VERSION}/flatcar_production_hetzner_image.bin.bz2 \
--labels os=flatcar,flatcar-channel=${CHANNEL}\
--description flatcar-${CHANNEL}-arm
Running hcloud-upload-image upload will take a few minutes to complete. If you need x86 and Arm snapshots, you can run both in parallel.
After it completes, you should see the following output:
1
Successfullyuploadedtheimage!image=167673693
You can verify this through the hcloud CLI:
1
2
3
4
$ hcloud image list --type=snapshot --selector=os=flatcar
ID TYPE NAME DESCRIPTION ARCHITECTURE IMAGE SIZE
167673693 snapshot - flatcar-beta-x86 x86 0.47 GB
167673694 snapshot - flatcar-beta-arm arm 0.41 GB
Make sure that your SSH Key is available in the current Hetzner Cloud project:
1
2
3
4
hcloud ssh-key list
# If not, you can upload the public key:hcloud ssh-key create --public-key-from-file ~/.ssh/<your-ssh-key>.pub --name my-ssh-key
Server configuration
Flatcar allows you to configure machine parameters, launch systemd units on startup and more via
Butane Configs
. These configs are then transpiled into Ignition JSON configs and given to booting machines.
We’re going to provide our Butane Config to Hetzner via the user-data flag.
The coreos-metadata.service saves metadata variables to /run/metadata/flatcar. Systemd units can use them with EnvironmentFile=/run/metadata/flatcar in the [Service] section when setting Requires=coreos-metadata.service and After=coreos-metadata.service in the [Unit] section.
As an example, this Butane YAML config will start an nginx Docker container and display the instance hostname:
variant:flatcarversion:1.0.0storage:directories:-path:/var/wwwsystemd:units:-name:nginx.serviceenabled:truecontents:|[Unit]Description=NGINXexampleAfter=docker.servicecoreos-metadata.serviceRequires=docker.servicecoreos-metadata.service[Service]EnvironmentFile=/run/metadata/flatcarTimeoutStartSec=0ExecStartPre=-/usr/bin/dockerrm--forcenginx1ExecStartPre=-/usr/bin/bash-c"echo \"Hello from ${COREOS_HETZNER_HOSTNAME}\" > /var/www/index.html"ExecStart=/usr/bin/dockerrun--namenginx1--volume"/var/www:/usr/share/nginx/html:ro"--pullalways--log-driver=journald--nethostdocker.io/nginx:1ExecStop=/usr/bin/dockerstopnginx1Restart=alwaysRestartSec=5s[Install]WantedBy=multi-user.target
Before we can create the server, we need to transpile this Butane configuration to the Ignition format:
1
docker run --rm -i quay.io/coreos/butane:latest < nginx-example.yaml > nginx-example.json
Create the server
Now that we have the snapshots, SSH Key and our Ignition config, we can finally create the first server:
1
2
3
4
5
6
7
8
9
# Get ID of the most recent flatcar snapshot for x86SNAPSHOT_ID=$(hcloud image list --type=snapshot --selector=os=flatcar --architecture=x86 -o=columns=id -o noheader --sort=created:desc | head -n1)hcloud server create \
--name flatcar-test \
--type cpx11 \
--image ${SNAPSHOT_ID}\
--ssh-key <your ssh key name or id> \
--user-data-from-file nginx-example.json
This will also take a minute or two to load the snapshot. After the process is finished, you will see the following output:
1
2
3
4
Server 48081481 created
IPv4: 37.27.83.94
IPv6: 2a01:4f9:c012:52f1::1
IPv6 Network: 2a01:4f9:c012:52f1::/64
To verify that nginx was properly started, run curl $(hcloud server ip flatcar-test).
You can log in via ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null core@$(hcloud server ip flatcar-test).
Known limitations
These Hetzner Cloud feature do not work with Flatcar:
Volume Automount: You need to mount volumes manually.
Setting & Resetting Root Passwords: You need to configure an SSH Key through the API or Ignition User Data.
ON THIS PAGE
Esc
Type to search. Use arrow keys to navigate results. Press Enter to open. Press Escape to close.