Introduction
In this tutorial, I will describe the setup Kubernetes v1.9.2 on Hetzner Cloud in 10 minutes. The final cluster will have:
- a basic Kubernetes cluster up and running on 2 nodes
- OpenEBS as dynamic storage provider
- Helm installed (with RBAC)
- nginx-ingress-controller
Video Tutorial
I’ve made a short asciinema clip of the entire installation.
Install and configure hetzner-kloud
In a shell run:
1 2 3 |
|
In Hetzner Cloud Console create a new project “demo” and add an API token “demo”. Copy the token and run:
1 2 |
|
And finally, add your SSH key (assuming you already have one in ~/.ssh/id_resa
) using:
1
|
|
And we are ready to go!
Deploy cluster
Deploying a cluster is as easy as:
1
|
|
This will create two servers of type CX11 in your account. So playing with this cluster will cost 0,01 EUR per hour (referring to current prices).
Access kubectl commands
In order to do anything with the cluster, you’ll need to ssh to the master to get access to kubectl command or setup your local kubectl with the cluster kubeconfig using:
1
|
|
Deploying OpenEBS
OpenEBS is a container native storage provider, which supports dynamic storage provisioning, which allows creating persistent volume claims to be automatically bound by created persistent volumes. On Hetzner Cloud, the installation is straight-forward:
1 2 |
|
You can check the status using kubectl get pod
and watch maya, and the operator becomes running.
Test the storage
First we define a PersistentVolumeClaim
, Deployment
and Service
in a file nginx.yaml
:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
|
Get the exact pod name of one nginx pod from kubectl get pod
and run.
1 2 3 |
|
Now you can kill the pods by:
1
|
|
And wait until they are re-scheduled again. Because of the persistent volume mounted in /usr/share/nginx/html
the data is available, even when pods are killed.
Helm and ingress
As Hetzner does not have a cloud provider for load balancers, we will use nginx-ingress-controller for traffic routing.
First, we install a helm, respecting RBAC:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|
And now we can install a lot of helm charts. Like this:
1
|
|
This will install an ingress controller, as described a year ago in my k8s bare-metal article.
Closing words!
Congratulations! You have a simple but working Kubernetes Cluster. Have fun.
Finally, I can say, that at the time of that article about deploying Kubernetes with CoreOS on bare-metal, I spent about a week for my first running cluster to deploy it. One year later I’ve learned go and made hetzner-kube my first project in that language. The alpha version for this tutorial was coded in just two evenings!
Have a nice week!