HomeDockerCreate a fully k3s Kubernetes cluster in minutes

Create a fully k3s Kubernetes cluster in minutes

In this article I portray how you can create a complete and manufacturing ready K3s Kubernetes cluster in Hetzner cloud in a few minutes. To do this we use the Vitobotta way as mentioned here: https://github.com/vitobotta/hetzner-k3s

Short step-by-step plan

We first create a config (as desired), which we pass with the Docker image.
Next, the sources that you defined in the config are created in Hetzner cloud via the Hetzner API. These include the servers, private community, firewall, load balancer for the API server for HA clusters.

What else will be installed:

• K3s to the nodes

• Hetzner Cloud Controller Manager to provision load balancers

• Hetzner CSI Driver to provision persistent volumes using Hetzner’s block storage

• Rancher System Upgrade Controller to make upgrades to a newer version of k3s easy and quick

Why Hetnzer cloud?

Hetzner Cloud is a cloud provider which offers a worthy service with the best performance/cost ratio in the market. With Hetzner’s Cloud Controller Manager and CSI driver you can provision load balancers and persistent volumes very easily.

Why K3s?

Because it uses much less memory and CPU, leaving more sources to workloads. It is also super quick to deploy because it’s a single binary.
Using this tool, creating a highly available k3s cluster with 3 masters for the control plane and 3 worker nodes takes about a couple of minutes only.

Requirements before we start:

• Windows (11 in our case) with a Docker Desktop installed.

• Git GUI for creating SSH keys but you can also use Putty Gen.

• Powershell ISE (but should be installed by default on Windows)

• An account on Hetzner cloud.

Create a new project in Hetzner and an account api key. Save the key because we will need it for the create.yaml.

Create the following folders and files:

• C:kluster

• C:klustercreate.yaml

• C:klusterssh

Start Git GUI en generate new SSH keys, save them in the ssh folder.

Note: the following create.yaml is an example, go to Vitobotta’s Github page for all options and other examples as well. For instance, you can determine yourself how many masters and workers you have.

If you want to create a High Available cluster you need at least 3 masters and 2 workers to be able to load stability. That is, if a master fails you can nonetheless entry and use your cluster. The same applies for your workload, if you have applications operating in the cluster, they will run on 1 of the 2 workers. If 1 fails, the other will take over so that your application is always up and operating.

• K3s_version, you can run hetzner-k3s releases to get a list of all K3s versions. Note: If you plan to install Rancher, it does not support the latest k3s versions. If you try that anyway, you will see a message:

Release "rancher" does not exist. Installing it now.
helm : Error: chart requires kubeVersion: < 1.22.0-0 which is incompatible with Kubernetes v1.22.3+k3s1
At line:1 char:1
+ helm upgrade --install --namespace cattle-system --set hostname=ranch ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (Error: chart re...es v1.22.3+k3s1:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError

• As for the Instance_type, https://www.hetzner.com/cloud on this page you will find an overview of the type and costs to make a fine choice.

hetzner_token: [your-hetzner-api-key]
cluster_name: [some-name]
kubeconfig_path: "./kubeconfig"
k3s_version: v1.22.3+k3s1
public_ssh_key_path: "~/.ssh/id_rsa.pub"
private_ssh_key_path: "~/.ssh/id_rsa"
verify_host_key: untrue
location: nbg1
schedule_workloads_on_masters: untrue
  instance_type: cpx21
  instance_count: 3
- name: small
  instance_type: cpx21
  instance_count: 2

Start Powershell ISE and run:

• cd C:kluster

docker run --rm -it -v ${PWD}:/cluster -v ${PWD}/ssh:/tmp/.ssh vitobotta/hetzner-k3s:v0.4.8 create-cluster --config-file /cluster/create.yaml

Give it a few minutes so the cluster can be created.
Finally a file is created:

• C:klusterkubeconfig

Copy it to:

• C:Usersyour-windows-user.kube

And rename the file to “config”, so without file extension.
Kubectl looks at this location for the config file with all keys.

You can use Powershell ISE to control your cluster.
A next step could be installing an Ingress controller. I will elaborate on this in another article.


Most Popular