Giter Site home page Giter Site logo

hetzner-flatcar's Introduction

hetzner-flatcar

A tool to deploy Flatcar Linux on Hetzner Cloud. Includes transpiling of Container Linux Config and reinstalling maschines on changes.

Build

go build .

Usage

  • create a config named config.toml with the values described in configuration.
  • create a container linux config template, see template for details
  • ./hetzner-flatcar hostname

This tool will establish a SSH session to the rescue os to run the flatcar-install script using goph. For authentication it uses the SSH agent, so ensure the private counterpart to the public key uploaded to Hetzner and referenced in the config is added to your SSH agent.

Configuration

[hcloud]
token = "<hetzner cloud token>"
server_type = "cx11"
location = "nbg1"
ssh_key = "<name of ssh key used for rescue and passed to template>"
private_network = "<private network server is attached to>"

[flatcar]
version = "3139.2.0"
config_template = "ignition.yml.gtpl"
# provide path to custom flatcar-install script
# if not provided will be downloaded from
# https://github.com/flatcar-linux/init/blob/flatcar-master/bin/flatcar-install
# install_script = "custom-install-script"
[flatcar.template_static]
nomad_version = "1.2.6"
consul_version = "1.11.4"

Template

The Container Linux Config template is rendered using text/template and is given this data:

  • Server - Server object as returned by Hetzner Cloud API
  • SSHKey - SSHKey object of the SSH Key used for rescue boot
  • Static - static data from config option flatcar.template_static as map[string]string
  • ReadFile(filename string) (string, error) - function to read a local file
  • Function(indent int, input string) string - function to indent strings

Afterwards it's transpiled into a Ignition file.

Take a look at the example config for a minimal example just creating a core user with the SSH Key used for rescue boot and setting the hostname to the maschine name.

injecting local files

The container linux config transpiler supports injecting local files (ref). Unfortunately that feature is not usable when not calling it using the CLI, because it relies on the value of a flag to determine the base path to search for files. As an alternative hetzner-flatcar supports the ReadFile template function to inject files into templates.

Example usage:

storage:
  files:
    - path: /etc/LICENSE
      filesystem: root
      contents:
        inline: |
{{ call .ReadFile "LICENSE" | call .Indent 12 }}

Custom template command

Instead of using the native go template, you can also use any other command (for example Helm). To do that provide your custom command in the configuration option flatcar.template_command. It will get passed the hostname as the first argument and Server and SSHKey in YAML format on stdin.

hetzner:
  server:
    name: ...
  sshkey:
    publickey: ...

Example script to render a helm template with a values file based on the hostname:

#!/bin/sh
cat - common.yaml "${1}.yaml" | yq -y . | helm template ignition -f -

Deployment procedure

  1. check whether vm with the name given as first parameter already exists
  2. create VM (if not already exists)
  3. render container linux config template with data from new or existing VM
  4. transpile container linux config into ignition file
  5. enable rescue boot on VM
  6. Startup or reboot VM (into rescue)
  7. upload flatcar-install script and rendered ignition config
  8. call flatcar-install and reboot

hetzner-flatcar's People

Contributors

thor77 avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.