Kubernetes the hard way on bare metal/VMs — V1.12

An all encompassing series designed for beginners. From VM configuration to K8S cluster building.

Image for post
Image for post
Kubernetes Logo

Introduction

After spending the past few months learning about Kubernetes, how to use it and how to set it up, I came to realise that whilst there are some excellent tutorials scattered around the internet, many presume a variety of situations such as:

  • You have access to multiple servers
  • You know all about networking
  • and many other things

Read the docs

I can’t stress enough how useful it is to read and understand the documentation on the main Kubernetes website to learn how to set clusters up in a variety of different ways.

Setting up the resources

I’ll be setting this up on libvirt using my home PC however you can replicate this with Virtualbox or physical servers allowing you to follow along from pretty much anywhere.

Configuring your VMs

Each VM will be set up with the following:

  • 2 CPUs
  • 2 x 40GB disk for a demo of using RAID in live
  • 1 NIC — Bridged
Image for post
Image for post
VMs used in this tutorial.

Operating System

I’ll be using Ubuntu Server for all of my controller and worker nodes. There is nothing Ubuntu specific about this tutorial other than apt usage for a couple of packages so feel free to use any Linux version you wish. Generally speaking you should be able to translate for your distribution without any issues.

Network

You will use kube-router. This is a purpose built, turnkey solution that provides high performance Kubernetes networking.
See the other options available here

Firewall

Presuming you’re at home, it’s likely your router already allows the internal communication between nodes but for external access (if you want external access), you’ll likely need to configure some port forwarding. If you’re unsure how to do this, check out portforward.com for examples.

Some info you’ll need later

The info below might be different for you depending on your network.

cat << EOF | sudo tee /etc/hosts
192.168.0.101 k8s-lb
192.168.0.210 k8s-controllers-lb
192.168.0.110 controller-0
192.168.0.111 controller-1
192.168.0.112 controller-2
192.168.0.120 worker-0
192.168.0.121 worker-1
192.168.0.122 worker-2
EOF

Installing packages

This step is nice and easy.

mkdir ~/k8s-the-hard-way-bare-metal
cd ~/k8s-the-hard-way-bare-metal

Get kubectl

This is the tool used to interact with the cluster — the snippet below will always pull the latest stable version.

curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.12.0/bin/linux/amd64/kubectl
chmod +x kubectl
sudo mv kubectl /usr/local/bin/

Setting up the Kubernetes Cluster

This guide was originally written for v1.12.0 and I’m currently playing with version 1.15 but there were a number of changes made in that, v.1.13 and v.1.14 that means this guide won’t work with either of those.
I’ll try and keep it up-to-date with the latest version for as long as I’m able however if anything doesn’t work, you may want to
refer to the changelogs to confirm nothing fundamental has changed in the service configurations since the writing of this article and you using it.

sudo apt install conntrack socat -y

Setting up cfssl & generating configs

Generate kubeconfigs and encryption key

Configuring controllers

Configuring the load balancer

Configuring the workers

Configure remote access

Configuring DNS

Testing the cluster

Conclusion

You should now have a fully functioning Kubernetes system that you can use either in (a pretty basic) production environment or as a single/multi node testing environment.

Written by

Kubernetes Admin/Pretend developer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store