Skip to content

jacqinthebox/vagrant-kubernetes

Repository files navigation

Bootstrap a single node Kubernetes cluster with Kubeadm and Vagrant

The purpose of this box is to quickly install a K8s cluster, roll your own microservices on top of it, break it down and see how it works. Inspired by this article: https://medium.com/@lizrice/kubernetes-in-vagrant-with-kubeadm-21979ded6c63.

I prefer bootstrapping with Kubeadm instead of Minikube or Docker for Desktop because this approach better reflects a production setup and it gives you the option to add worker nodes as well.

What is installed:

  • Ubuntu 18.04.02 LTS
  • Docker
  • Kubeadm
  • Single node Kubernetes cluster
  • Flannel
  • Nginx Ingress
  • Kubernetes Dashboard
  • Helm

Customizations:

  • The Nginx ingress controller will also listen to 1433 (mssql). See the configmap.
  • it is set to use hostnetwork is set to true to have it work on a single node bare metal cluster
  • the Dashboard is set to use NodePort to be able to browse to it via its TCP port instead of using kubectl proxy.

Instructions

Install Vagrant and Virtualbox.

Create some folders, e.g.

mkdir -p ~/vagrant/single-master
cd ~/vagrant/single-master

Then fetch the Vagrantfile:

wget https://raw.githubusercontent.com/jacqinthebox/vagrant-kubernetes/master/Vagrantfile

Then edit the Vagrantfile.
Adjust the variables on top to match your IP config and cluster- and SAN names**

variables

For example, when on Linux: To find a free IP address in your subnet, type e.g. nmap -sP 192.168.1.0/24 To find your bridge interface, type net add To find your Gateway type netstat -rn or ip r
To find your DNS type nmcli dev show | grep DNS

In Windows ipconfig /all will do the trick.

Then bootstrap the cluster like so:

vagrant up node01

Sit back and wait for it to finish.

Log in to the Dashboard

Note the Dashboard url and the token in the script output. Copy the token and head over to the Dashboad url. Paste the token into the logon form.

Copy the Kube config

For example

scp [email protected]:/home/vagrant/.kube/config .

And then add it to your current config like so (assuming your $KUBECONFIG is empty):

export KUBECONFIG=$KUBECONFIG:$HOME/.kube/config:$HOME/vagrant/single-master/config

https://kubernetes.io/docs/tasks/access-application-cluster/configure-access-multiple-clusters/#set-the-kubeconfig-environment-variable

Optional: deploy example application

kubectl apply -f https://raw.githubusercontent.com/jacqinthebox/vagrant-kubernetes/master/microbot.yaml

How does this work?

I really wanted the cluster to have a custom clustername, else they are all named kubernetes :) This can only be done with a configfile for kubeadm.

This is why the script takes in 3 arguments: clustername, san1 and san2.

With these arguments, a configfile is created for the kubeadm init:

apiVersion: kubeadm.k8s.io/v1beta1
kind: ClusterConfiguration
clusterName: $1
networking:
  podSubnet: 10.244.0.0/16
apiServer:
  CertSANs:
  - "$2"
  - "$3"
etcd:
  local:
    serverCertSANs:
      - "$2"
      - "$3"
    peerCertSANs:
      - "$2"
      - "$3"

Just have a further look in the script to see how I constructed the cluster. Of course I am open for suggestions.

Disclaimer

Do not use this in production. Vagrant boxes are meant for developing and testing.

Resources

kubernetes/kubernetes#33618
kubernetes/kubeadm#1330
https://godoc.org/k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1beta1
https://github.com/kubernetes/kubeadm/blob/master/docs/design/design_v1.9.md
kubernetes/kubernetes#68333
https://blog.scottlowe.org/2018/08/21/bootstrapping-etcd-cluster-with-tls-using-kubeadm/
https://medium.com/@lizrice/kubernetes-in-vagrant-with-kubeadm-21979ded6c63

About

A single node Kubernetes cluster with Vagrant

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages