Skip to content

maluio/kube-lab

Repository files navigation

Kube Lab

A kubernetes lab environment that

  • mixes kubespray with custom ansible playbooks to boostrap kubernetes clusters in different configurations
  • uses Jupyter Notebooks to run commands in those clusters and stores the outputs for reproducibility and documentation

Please note: The kubernetes clusters created by this project are for educational purposes only.

Labs / Notebooks

Running commands in Jupyter Notebooks makes it easy to fiddle with the cluster while saving the output. GitHub and Gitlab render the notebooks in the browser which is a very convient way to document what you have been doing.

Here are some of the notebooks I have been working on (most of which are still work in progress):

Development / Create your own labs

Running the project locally spins up Jupyter Labs in a container.

Requirements

  • A container runtime (docker, containerd, ...)
  • A Hetzner Cloud account and a HCLOUD_TOKEN

Run

# Build the image
$ bin/container/build.sh
# Run the container
$ HCLOUD_TOKEN=<YOUR_HCLOUD_TOKEN> bin/container/start.sh

Please check standard output. You'll find the url to open Jupyter Labs locally in you browser.

# Provisioning the remote servers
# This takes 10-20 minutes
$ docker exec kube-lab bin/cluster/provision.sh

You can now use Jupyter Labs to run your experiments in the cluster.

Stop

# Attention: This script not only stops the container but also deletes the whole cluster!
$ bin/container/stop.sh

Project structure

  • On building the image the kubespray repo is checked out in the image in a path outside the project root.
  • The inventory/mycluster directory is a copy of kubespray'sinventory/sample directory. Everything in there concerns the ansible config for kubespray.
  • Modifications to the configuration happen either in inventory/mycluster or by providing -e PARAMETER=value to the ansible-playbook command.
├── Dockerfile
├── bin   # project specific scripts
│   ├── cluster
│   │   ├── ...
│   ├── container
│   │   ├── build.sh
│   │   ├── entrypoint.sh
│   │   ├── start.sh
│   │   └── stop.sh
│   └── git_hooks
│       └── pre_commit.sh
├── manifests # manifests used as part of the labs
│   └── ...
├── mycluster # cluster configuration for kubespray based on its sample configuration
│   ├── group_vars
│   │   ├── ...
│   └── hosts.yml
├── notebooks # notebooks / labs 
│   ├── apps.ipynb
│   ├── ...
├── playbooks # custom playbooks specific to this project
│   ├── create.yml
│   ├── ...
└── requirements.txt # python dependencies that are added to the dependencies requried by kubespray