Giter Club home page Giter Club logo

k8s-hetzner's Introduction

k8s-hetzner-cloud

Kubernetes Terraform installer for Hetzner bare-metal.

k8s-cluster

Initial setup

Clone the repository and install the dependencies:

$ git clone https://github.com/felipecruz91/k8s-hetzner.git
$ cd k8s-hetzner
$ terraform init

Note that you'll need Terraform v0.13 or newer to run this project.

Note that, before running the project, you'll have to create an access token for Terraform to connect to the Hetzner Cloud API.

Once you have the token, create the hetzner-api-token.txt file and paste it in there.

Using the token, create the TF_VAR_hcloud_token environment variable:

$ export TF_VAR_hcloud_token=$(cat hetzner-api-token.txt)

Building the Kubernetes VM image with Packer

Prepare snapshot image, so the terraform will use it to create and up nodes of the cluster.

Run once the command below:

$ cd images && \
    packer build image-master.json

For containerd image use command packer build image-master-containerd.json.

Now we have a snapshot and we need to know it's ID.

To do this run:

$ curl -H "Authorization: Bearer $TF_VAR_hcloud_token" 'https://api.hetzner.cloud/v1/images'

and find the image's ID with the name described in the image-master-containerd.json and/or image-master.json files. Put pointed ID in the variables.tf config file.

Usage

Create a bare-metal Kubernetes cluster with one master and 3 worker nodes:

$ terraform apply \
 -var master_location=nbg1 \
 -var master_server_type=cpx11 \
 -var worker_nodes_count=3 \
 -var worker_server_type=cx11 \
 -var worker_location=nbg1

This will do the following:

  • provisions three bare-metal servers with Ubuntu 18.04 LTS (the size of the master and the node may be different but must remain in the same type of architecture)
  • connects to the master server via SSH and installs Docker CE and kubeadm apt packages
  • runs kubeadm init on the master server and configures kubectl
  • downloads the kubectl admin config file on your local machine and replaces the private IP with the public one
  • (obsolete) creates a Kubernetes secret with the Weave Net password
  • (obsolete) installs Weave Net with encrypted overlay
  • installs calico CNI
  • starts the nodes in parallel and installs Docker CE and kubeadm
  • joins the nodes in the cluster using the kubeadm token obtained from the master

Scale up by increasing the number of nodes:

$ terraform apply \
 -var worker_nodes_count=4

There are two useful scripts which can be used to create and destroy a cluster:

upcl.sh
docl.sh

Tear down the whole infrastructure with:

terraform destroy -force

Remote control

After applying the Terraform plan you'll see several output variables like the master public IP, the kubeadm join command and the current workspace admin config.

In order to run kubectl commands against the Hetzner cluster you can use the kubectl_config output variable:

$ export KUBECONFIG="$(pwd)/$(terraform output --raw kubectl_config)"
$ kubectl --insecure-skip-tls-verify get nodes -o wide

NAME       STATUS   ROLES    AGE     VERSION   INTERNAL-IP     EXTERNAL-IP   OS-IMAGE             KERNEL-VERSION       CONTAINER-RUNTIME
master     Ready    master   3m45s   v1.24.5   78.47.249.188   <none>        Ubuntu 18.04.5 LTS   4.15.0-124-generic   docker://19.3.6
worker-0   Ready    <none>   3m28s   v1.24.5   94.130.73.91    <none>        Ubuntu 18.04.5 LTS   4.15.0-124-generic   docker://19.3.6
worker-1   Ready    <none>   3m23s   v1.24.5   157.90.17.247   <none>        Ubuntu 18.04.5 LTS   4.15.0-124-generic   docker://19.3.6
worker-2   Ready    <none>   3m26s   v1.24.5   157.90.24.227   <none>        Ubuntu 18.04.5 LTS   4.15.0-124-generic   docker://19.3.6

k8s-hetzner's People

Contributors

felipecruz91 avatar orarun avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

k8s-hetzner's Issues

Hetzner Load Balancer

Is there support for Hetzner load balancer when using these installer scripts? I'm having some issues to get things working.

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.