Kubernetes cluster on HETZNER cloud

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.

CommunityNew

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

Related articles6

Introduction to GitOps

Introduction to GitOps

GitOps serves to make the process of development and operations more developer-centric. It applies DevOps practices with Git as a single source of truth for infrastructure automation and deployment, hence the name “Git Ops.” But before getting deeper into what is...

Kaniko: How Users Can Make The Best Use of Docker

Kaniko: How Users Can Make The Best Use of Docker

Whether you love or hate containers, there are only a handful of ways to work with them properly that ensures proper application use with Docker. While there do exist a handful of solutions on the web and on the cloud to deal with all the needs that come with running...

Cilium: A Beginner’s Guide To Improve Security

Cilium: A Beginner’s Guide To Improve Security

A continuation from the previous series on eBPF and security concerns; it cannot be reiterated enough number of times how important it is for developers to ensure the safety and security of their applications. With the ever expanding reach of cloud and software...

How to clean up disk space occupied by Docker images?

How to clean up disk space occupied by Docker images?

Docker has revolutionised containers even if they weren't the first to walk the path of containerisation. The ease and agility docker provide makes it the preferred engine to explore for any beginner or enterprise looking towards containers. The one problem most of...

Parsing Packages with Porter

Parsing Packages with Porter

Porter works as a containerized tool that helps users to package the elements of any existing application or codebase along with client tools, configuration resources and deployment logic in a single bundle. This bundle can be further moved, exported, shared and distributed with just simple commands.

eBPF – The Next Frontier In Linux (Introduction)

eBPF – The Next Frontier In Linux (Introduction)

The three great giants of the operating system even today are well regarded as Linux, Windows and Mac OS. But when it comes to creating all purpose and open source applications, Linux still takes the reign as a crucial piece of a developer’s toolkit. However, you...