xbernpa / vagrant-kubernetes-lab

Local vagrant kubernetes cluster with a master and worker node
MIT License
27 stars 27 forks source link

vagrant-kubernetes-lab

This project is to provide a simple local Kubernetes cluster with a master and a worker node for testing purpose.

Vagrant was chosen for being able to create the cluster either on linux, windows and mac hosts.

Prequirements

Default provisioning

Vagrant up will provide 2 Ubuntu Xenial VMs for a kubernetes cluster with these features by default :

Options

network

By default, we will use the Weave-Net driver but you can override it with flannel like this:

 vagrant --network=flannel up

mount

It is possible to mount a directory from the host to the /data directory on each node. This option could be used, for example, to make git repositories local to the host available to be used in the cluster.

The --mount=<pathOnHost> option allows to choose the directory on the host that will be mounted to /data. If that option is not specified, nothing will be mounted.
For example, run the command:

 vagrant --mount=/home/user/git up

dockerhub login

You can provide your username and password in order to do a "docker login" on each node of the cluster. This will allow you to pull private images from the Docker registry.

 vagrant --docker-username=myUser --docker-password=myPassword up

Kubeconfig

After installation, a copy of the admin.conf generated by kubeadm is available on the host in the /vagrant/kubeconfig directory, which is a shared folder inside the Git repo ./kubeconfig

Even if kubectl can be used within the guests, it is suggested that you copy the admin.conf as config in your ~/.kube/ directory on the host to able to do kubectl proxy and kubectl port-forward per example.

Or you can simply execute:

export KUBECONFIG=`pwd`/kubeconfig/admin.conf
kubectl get nodes

And you should see:

NAME        STATUS    ROLES     AGE       VERSION
k8smaster   Ready     master    10m       v1.9.0
k8sworker   Ready     <none>    5m        v1.9.0

Extra features

Multiple optionnal extra softwares has been tested with this cluster and are available if needed.

Here is the current list by category :

Ingress

Install everything (Quick start)

Note that if you want to install everything, you can simply run the following script (providing you have kubectl installed):

vagrant up
bash scripts/install-all-features.sh
kubectl get pods --all-namespaces -o wide

And repeat the get "kubectl get pods" command as long as the pods are not up and running.

Open dashboards

Kubernetes

Follow the instructions printed in the console:

bash scripts/open-dashboard.sh

Grafana

Note that you might have to reload the page in your browser.

bash scripts/open-grafana.sh

Weave Scope

Note that you might have to reload the page in your browser.

bash scripts/open-weavescope.sh