|
| 1 | +--- |
| 2 | +title: Running Flatcar on Brightbox |
| 3 | +linktitle: Running on Brightbox |
| 4 | +weight: 10 |
| 5 | +--- |
| 6 | + |
| 7 | +These instructions will walk you through using Flatcar on Brightbox, importing custom image, and running your first server using the command line interface. Please note that Brightbox is powered by OpenStack: it is not a mistake if we refer to OpenStack images and specific variables. |
| 8 | + |
| 9 | +## Import the image |
| 10 | + |
| 11 | +While [Brightbox][brightbox] provides Flatcar images for Beta, Stable and LTS channels it is possible to import your own Flatcar image in Brightbox using the [CLI][cli]. |
| 12 | + |
| 13 | +For example, to upload the Alpha channel of Flatcar: |
| 14 | + |
| 15 | +```bash |
| 16 | +$ brightbox images register \ |
| 17 | + --arch=x86_64 --name=flatcar-alpha \ |
| 18 | + --url=https://alpha.release.flatcar-linux.net/amd64-usr/current/flatcar_production_openstack_image.img |
| 19 | +$ brightbox images list --type=upload |
| 20 | + id owner type created_on status size name |
| 21 | +--------------------------------------------------------------------------------- |
| 22 | + img-xoufd acc-jg5aa upload 2023-12-05 private 8694 flatcar-alpha (x86_64) |
| 23 | +--------------------------------------------------------------------------------- |
| 24 | +``` |
| 25 | + |
| 26 | +## Butane Configs |
| 27 | + |
| 28 | +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. Jump over to the [docs to learn about the supported features][butane-configs]. We're going to provide our Butane Config to Brightbox via the user-data flag. Our Butane Config will also contain SSH keys that will be used to connect to the instance. |
| 29 | + |
| 30 | +As an example, this Butane YAML config will start an Nginx Docker container and display the instance hostname: |
| 31 | + |
| 32 | +```yaml |
| 33 | +variant: flatcar |
| 34 | +version: 1.0.0 |
| 35 | +passwd: |
| 36 | + users: |
| 37 | + - name: core |
| 38 | + ssh_authorized_keys: |
| 39 | + - ssh-rsa ABCD... |
| 40 | +storage: |
| 41 | + directories: |
| 42 | + - path: /var/www |
| 43 | +systemd: |
| 44 | + units: |
| 45 | + - name: nginx.service |
| 46 | + enabled: true |
| 47 | + contents: | |
| 48 | + [Unit] |
| 49 | + Description=NGINX example |
| 50 | + After=docker.service coreos-metadata.service |
| 51 | + Requires=docker.service coreos-metadata.service |
| 52 | + [Service] |
| 53 | + EnvironmentFile=/run/metadata/flatcar |
| 54 | + TimeoutStartSec=0 |
| 55 | + ExecStartPre=-/usr/bin/docker rm --force nginx1 |
| 56 | + ExecStartPre=-/usr/bin/bash -c "echo 'Hello from ${COREOS_OPENSTACK_HOSTNAME}' > /var/www/index.html" |
| 57 | + ExecStart=/usr/bin/docker run --name nginx1 --volume "/var/www:/usr/share/nginx/html:ro" --pull always --log-driver=journald --net host docker.io/nginx:1 |
| 58 | + ExecStop=/usr/bin/docker stop nginx1 |
| 59 | + Restart=always |
| 60 | + RestartSec=5s |
| 61 | + [Install] |
| 62 | + WantedBy=multi-user.target |
| 63 | +``` |
| 64 | +
|
| 65 | +Transpile it to Ignition JSON: |
| 66 | +
|
| 67 | +```bash |
| 68 | +cat butane.yaml | docker run --rm -i quay.io/coreos/butane:release > ignition.json |
| 69 | +``` |
| 70 | + |
| 71 | +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. |
| 72 | + |
| 73 | +## Launch machine |
| 74 | + |
| 75 | +Boot the machines with the CLI, referencing the image ID from the import step above or using an official image ID (`brightbox images list --type=official`) and your [JSON file from ct][cl-configs]: |
| 76 | + |
| 77 | +```shell |
| 78 | +$ brightbox servers create --cloud-ip=true --user-data-file=./config.json img-xoufd |
| 79 | +``` |
| 80 | + |
| 81 | +Your first Flatcar instance should now be running. The only thing left to do is find an IP and SSH in. |
| 82 | + |
| 83 | +```shell |
| 84 | +$ brightbox servers show $THE_INSTANCE_ID |
| 85 | +... |
| 86 | + cloud_ipv4s: 109.107.37.145 |
| 87 | +... |
| 88 | +``` |
| 89 | + |
| 90 | +Finally SSH into an instance, note that the user is `core`: |
| 91 | + |
| 92 | +```shell |
| 93 | +$ curl 109.107.37.145 |
| 94 | +Hello from srv-f0lo3.gb1.brightbox.com |
| 95 | + |
| 96 | +core@srv-f0lo3 ~ $ |
| 97 | +core@srv-f0lo3 ~ $ systemctl status nginx |
| 98 | +● nginx.service - NGINX example |
| 99 | + Loaded: loaded (/etc/systemd/system/nginx.service; enabled; preset: enabled) |
| 100 | + Active: active (running) since Tue 2023-12-05 16:25:06 UTC; 1min 53s ago |
| 101 | +... |
| 102 | +``` |
| 103 | + |
| 104 | +## Using Flatcar Container Linux |
| 105 | + |
| 106 | +Now that you have a machine booted it is time to play around. Check out the [Flatcar Container Linux Quickstart][quickstart] guide or dig into [more specific topics][doc-index]. |
| 107 | + |
| 108 | +[butane-configs]: ../../provisioning/config-transpiler |
| 109 | +[brightbox]: https://cloud.brightbox.com/ |
| 110 | +[cli]: https://www.brightbox.com/docs/reference/clig |
| 111 | +[doc-index]: ../../ |
| 112 | +[quickstart]: ../ |
0 commit comments