By Ian - Tue Feb 25 2020 - 10 min read
One of the big advantages of using Docker is the promise of an easy deployment process. And while this is definitely the case for smaller application with, for instance, docker compose, it's not really a production ready solution. Docker compose also doesn't have the (subjectively) very awesome autoscaling features and automatic rollbacks. Lots of organizations are choosing either a managed kubernetes solution by gcloud/Amazon, or choosing for a massive vendor lock in with Amazon's ECS or Fargate.
I'm going to show you a very easy way to launch your stack on kubernetes with a beautiful UI, and no vendor lock in using Rancher. And don't worry, it's a lot easier than you think!
In this tutorial we're just going to create a Kubernetes cluster with Rancher running on Hetzner servers, for a grand total of €5,- a month. No fancy stuff just yet. In another tutorial I'll show you how to run your services on the cluster, including a VPN and automatic SSL.
I went with Hetzner because they offer very affordable servers at a prime location for european users. You also pay by the minute with Hetzner. So following along with this tutorial is going to cost you in the range of cents.
Okay first off you're going to need a few things:
Access
→ Tokens
, and create a new token.)Add SSH key
Use the following command to copy your ssh keys to clipboard: (it should end in something like "[user]@[machine]")
cat ~/.ssh/id_rsa.pub | pbcopy
Add a server. (go to project → server → add server)
SSH into your newly created server (you can find the IP address in the server tab of the Hetzner console):
ssh root@[IP_ADDRESS]
Setup Docker on your remote host.
sudo apt-get update
sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
You can do two things right now:
I would recommend setting up a domain if you're planning on running a production build based on this tutorial. Mainly because using a domain enables SSL on your Rancher WebUI. If you want to get through this tutorial and go for production later: just use the IP and figure out the domain once you're doing production level stuff.
Run the Rancher image!
For no domain run:
sudo docker run -d --restart=unless-stopped -p 80:80 -p 443:443 rancher/rancher
For rancher with domain run:
sudo docker run -d --restart=unless-stopped -p 80:80 -p 443:443 rancher/rancher --acme-domain <YOUR_DOMAIN>
In Rancher go to Tools
→ Drivers
→ Add Node Driver
https://github.com/JonasProgrammer/docker-machine-driver-hetzner/releases/download/2.1.0/docker-machine-driver-hetzner_2.1.0_linux_amd64.tar.gz
https://storage.googleapis.com/hcloud-rancher-v2-ui-driver/component.js
storage.googleapis.com
Clusters
→ Add Cluster
in Rancher and you should see Hetzner as an infrastructure supplier.Add Cluster
screen
Add Node Template
and enter the API Token we created in the 'setting stuff up' stepEnter a cluster name, select etcd
, Control Pane
and Worker
for your node and press create
Awww yisss! You've just created a fully operational Kubernetes cluster on Rancher!🚀 You can manually scale instances up and down.
If you're already familliar with Kubernetes, you can find the .kube/config
file under Cluster
→ Kubeconfig
.
If you're not: don't worry! We're going to walk you through setting up some extra cool features (like a VPN) and launching your first application on the cluster later.