How to build a Kubernetes cluster on HETZNER with k3s

by | 28.03.2021 | Engineering

HETZNER is a german cloud provider having very competitive prices for linux-based VMs. It’s a great place to run Kubernetes, as HETZNER provides many integrations with their systems we can leverage when running Kubernetes:

  • CSI Integration
  • Terraform integration
  • Loadbalancers

At p3r we’re building many tools for Kubernetes – one of them is apollo, which we will use to build a k3s cluster with hcloud Volumes as our default StorageClass using the hcloud csi-driver.

Provision the VMs

First, create 3 Ubuntu 20.04 VMs at HETZNER with a size that fits your needs (CX31 is our default), name them master-0, node-0 and node-1 and add your SSH key to them.

Download apollo

You need git, python3 and pip3 for the following steps.

git clone https://gitlab.com/p3r.one/apollo
cd apollo
pip3 install -r requirements.txt
mkdir -p inventory/hcloud

Configure your Kubernetes cluster

Add the following configuration to inventory/hcloud/hosts.yml:

all:
  hosts:
    master-0:
      ansible_host: IP_OF_MASTER0
    node-0:
      ansible_host: IP_OF_NODE0
    node-1:
      ansible_host: IP_OF_NODE1
  children:
    master:
      hosts:
        master-0:
    node:
      hosts:
        node-0:        
        node-1:
    k3s_cluster:
      children:
        master:
        node:

Add the following configuration to inventory/hcloud/vars.yml:

ansible_ssh_user: root
csi:
  provider: hcloud

Set your Hetzner API key (needed for the CSI integration):

export HCLOUD_TOKEN=MYHCLOUDTOKEN

Install your cluster

Run the following command to setup your k3s cluster:

ansible-playbook apollo.yml -e @inventory/hcloud/vars.yml -i inventory/hcloud/hosts.yml --flush-cache

The kubeconfig for your new cluster can be found in inventory/kubeconfig.yml. You can use Lens to work with your new Kubernetes cluster.

Join the Community

The DevOps Awareness Program

Subscribe to the newsletter

Join 100+ cloud native ethusiasts

#wearep3r

Join the community Slack

Discuss all things Kubernetes, DevOps and Cloud Native

More stories from our blog

What’s new in Keptn v0.9.0?

What’s new in Keptn v0.9.0?

Keptn recently came out with its new big update with the release of version 0.9.0. We will see what this update contains in this article, along with all of the new features, bug fixes, enhancements and all. Let's start! What is Keptn? Keptn is simply an event-based...

What’s New in Lens 5.2?

What’s New in Lens 5.2?

Lens 5.2 is now available, with many new and improved capabilities and numerous fascinating enhancements and bug fixes! Support for Apple's Silicon chip (M1), enhanced user experience for adding/removing clusters, Monaco Editor Integration and more. Let's dive...

Linkerd: Looming on Service Meshes

Linkerd: Looming on Service Meshes

Microservices and service meshes have become a staple of the industry as companies realize the full potential of creating an independent architecture that allows for easier scale up, agile development, resilience and streamlined deployment. Many of these applications...

What’s new in Flux v0.17.0?

What’s new in Flux v0.17.0?

Flux2 came with its new update a while ago, and it is sheer exciting for the users because it brought a lot of new features. It also made a lot of new enhancements and updates. We will take a look at the entire catalogue in this article. So, without further a due,...

What’s new in Portainer v2.7.0 BE?

What’s new in Portainer v2.7.0 BE?

A few days ago, Portainer Business Edition came up with their new update. It is quite a massive update with many new features, bug fixes, enhancements and much more. In this article, we will see all of those in a nutshell. Let's start What is Portainer? Portainer is...

DVC (Git For Data): A Complete Intro

DVC (Git For Data): A Complete Intro

As a data scientist or ML engineer, have you ever faced the inconvenience of experimenting with the model? When we train the model, the model file is generated. Now, if you want to experiment with some different parameters or data, generally people rename the existing...

Recap of the Cloud Native Meetup Saar #3

Recap of the Cloud Native Meetup Saar #3

We are looking back on a very successful third edition of our Cloud Native Meetup Saar #3! Togetherer with our co-host anynines, we enjoyed a fun afternoon filled with great speakers, intriguing topics and thoughtful conversations! We welcomed a total of three...

Portainer Ambassador Series ft. Fabian Peter

Portainer Ambassador Series ft. Fabian Peter

Portainer arranged a fun and informative discussion through a one-hour special named “Ambassador Series” on 1st July 2021. It was pretty amazing to see Savannah Peterson as the host and two other guests. One is our very own CEO of p3r.one, Fabian Peter and the other...

What’s new in Longhorn v1.2.0?

What’s new in Longhorn v1.2.0?

Longhorn came with their new update. It is full of surprises. We will peel off one by one to see all the latest updates, features, bug fixes and much more. This one is a much-awaited update, and we will see all of it in a moment. So, without further a due, let's...

Kubernetes Stateful Friend: What’s more to etcd?

Kubernetes Stateful Friend: What’s more to etcd?

The Kubernetes control plane consists of various components, and one of such components is etcd. Anyone starting to learn k8s come across it and memorizes quickly that it’s a key-value pair for Kubernetes with persistence store. But, what’s more to it? Why do we need...

Interested in what we do? Looking for help? Wanna talk about software strategy?