Go to file
Karim Naufal ee7a0af8aa
Merge pull request #43 from mnencia/taint
Taint control-plane nodes with node-role.kubernetes.io/master:NoSchedule
2022-02-07 15:56:39 +01:00
.github/workflows Rename directory 2022-01-13 10:29:22 +01:00
.images Tweaked Readme 2022-01-05 16:28:19 +01:00
hetzner added possibility to use latest containers for CCM and CSI 2022-01-15 09:04:21 +01:00
kured removed generated kured kustomization from git 2022-02-07 10:05:02 +01:00
templates Merge pull request #43 from mnencia/taint 2022-02-07 15:56:39 +01:00
.gitignore removed generated kured kustomization from git 2022-02-07 10:05:02 +01:00
agents.tf remove root from ssh_args... 2022-02-07 13:19:06 +01:00
data.tf added kured and fixed initial ignition disk partitioning 2022-02-07 08:46:10 +01:00
LICENSE initial commit 2021-07-30 10:12:37 +02:00
locals.tf remove root from ssh_args... 2022-02-07 13:19:06 +01:00
main.tf added kured and fixed initial ignition disk partitioning 2022-02-07 09:36:21 +01:00
master.tf Merge pull request #44 from phaer/fix-ssh-identity 2022-02-07 15:45:42 +01:00
output.tf initial k3s on MicroOS on Hetzner ok 2022-02-06 08:40:51 +01:00
providers.tf remove empty provider blocks 2022-01-23 14:31:27 +01:00
README.md added kured and fixed initial ignition disk partitioning 2022-02-07 08:46:10 +01:00
servers.tf remove root from ssh_args... 2022-02-07 13:19:06 +01:00
terraform.tfvars.example added kured and fixed initial ignition disk partitioning 2022-02-07 09:36:21 +01:00
variables.tf added kured and fixed initial ignition disk partitioning 2022-02-07 09:36:21 +01:00
versions.tf Make version of CCM / CSI configurable 2022-01-13 14:28:00 +01:00

Contributors Forks Stargazers Issues MIT License


Logo

Kube-Hetzner

A highly optimized and auto-upgradable, HA-able & Load-Balanced, Kubernetes cluster powered by k3s-on-MicroOS and deployed for peanuts on Hetzner Cloud 🤑 🚀



About The Project

Hetzner Cloud is a good cloud provider that offers very affordable prices for cloud instances, with data center locations in both Europe and the US.

The goal of this project is to create an optimal and highly optimized Kubernetes installation that is easily maintained, secure, and automatically upgrades. We aimed for functionality as close as possible to GKE's auto-pilot. In order to achieve this, we built on the shoulders of giants, by choosing openSUSE MicroOS as the base operating system, and k3s as the Kubernetes engine.

Please note that we are not affiliated to Hetzner, this is just an open source project striving to be an optimal solution for deploying and maintaining Kubernetes on Hetzner Cloud.

Features

  • Maintenance free with auto-upgrade to the latest version of MicroOS, k3s, Hetzner CCM and CSI.
  • Proper use of the underlying Hetzner private network to remove the need for encryption and make the cluster both fast and secure.
  • Automatic HA with the default setting of two control-plane and agents nodes.
  • Ability to add or remove as many nodes as you want while the cluster stays running.
  • Automatic Traefik ingress controller attached to a Hetzner load balancer with proxy protocol turned on.
  • (Optional) Out of the box config of Traefik with SSL certficate auto-generation.

It uses Terraform to deploy as it's easy to use, and Hetzner provides a great Hetzner Terraform Provider.

Product Name Screen Shot

Getting started

Follow those simple steps, and your world's cheapest Kube cluster will be up and running in no time.

✔️ Prerequisites

First and foremost, you need to have a Hetzner Cloud account. You can sign up for free here.

Then you'll need to have terraform and kubectl cli installed. The easiest way is to use the gofish package manager to install them.

gofish install terraform
gofish install kubectl

The Hetzner cli hcloud is also useful to have, mainly for debugging without having to use the Hetzner website. See how to install it here.

💡 [Do not skip] Creating the terraform.tfvars file

  1. Create a project in your Hetzner Cloud Console, and go to Security > API Tokens of that project to grab the API key. Take note of the key!
  2. Either, generate a passphrase-less ed25519 SSH key-pair for your cluster, unless you already have one that you'd like to use. Take note of the respective paths of your private and public keys. Or, for a key-pair with passphrase or a device like a Yubikey, make sure you have have an SSH agent running and your key is loaded (ssh-add -L to verify) and set private_key = null in the following step.
  3. Copy terraform.tfvars.example to terraform.tfvars, and replace the values from steps 1 and 2.
  4. (Optional) There are other variables in terraform.tfvars that could be customized, like Hetzner region, and the node counts and sizes.

🎯 Installation

terraform init
terraform apply -auto-approve

It will take around 12 minutes to complete, and then you should see a green output with the IP addresses of the nodes. Then you can immediately kubectl into it (using the kubeconfig.yaml saved to the project's directory after the install).

Just using the command kubectl --kubeconfig kubeconfig.yaml would work, but for more convenience, either create a symlink from ~/.kube/config to kubeconfig.yaml, or add an export statement to your ~/.bashrc or ~/.zshrc file, as follows (you can get the path of kubeconfig.yaml by running pwd):

export KUBECONFIG=/<path-to>/kubeconfig.yaml

Usage

When the cluster is up and running, you can do whatever you wish with it! 🎉

Scaling nodes

You can scale the number of nodes up and down without any issues. If you are going to scale down, just make sure to properly kubectl drain the nodes in question first. Then just edit these variables in terraform.tfvars and re-apply terraform with terraform apply -auto-approve.

For instance:

servers_num = 2
agents_num = 3

Useful commands

  • List your nodes IPs, with either of those:
terraform outputs
hcloud server list
  • See the Hetzner network config:
hcloud network describe k3s
  • Log into one of your nodes (replace the location of your private key if needed):
ssh root@xxx.xxx.xxx.xxx -i ~/.ssh/id_ed25519 -o StrictHostKeyChecking=no

Automatic upgrade

By default, k3os and its embedded k3s instance get upgraded automatically on each node, thanks to its embedded system upgrade controller.

You can also choose to automatically kustomize the Hetzner CCM and CSI to set their container images to "latest" with an imagePullPolicy of "Always". That means that when the nodes upgrade, these container images will be automatically upgraded too. For more info on this, see terraform.tfvars.example.

If you wish to turn off automatic upgrade on a specific node, you need to take out the label k3os.io/upgrade=latest. It can be done with the following command:

kubectl label node <nodename> 'k3os.io/upgrade'-

Takedown

If you want to takedown the cluster, you can proceed as follows:

kubectl delete -k hetzner/csi
kubectl delete -k hetzner/ccm
hcloud load-balancer delete traefik
terraform destroy -auto-approve

Also, if you had a full-blown cluster in use, it would be best to delete the whole project in your Hetzner account directly as operators or deployments may create other resources during regular operation.

Contributing

Any contributions you make are greatly appreciated.

  1. Fork the Project
  2. Create your Branch (git checkout -b AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin AmazingFeature)
  5. Open a Pull Request

Acknowledgements

  • k-andy was the starting point for this project. It wouldn't have been possible without it.
  • Best-README-Template that made writing this readme a lot easier.
  • Hetzner Cloud for providing a solid infrastructure and terraform package.
  • Hashicorp for the amazing terraform framework that makes all the magic happen.
  • Rancher for k3s and k3os, robust and innovative technologies that are the very core engine of this project.