Skip to content

ipccheng/k8s-home-lab

Repository files navigation

Fast Automated Kubernetes Home Lab Setup with Virtualbox, Vagrant and Ansible

The purpose of this project is to build a K8S environment quickly with Virtualbox, Ansible and Vagrant.


Tested Environment

  • Ubuntu: 18.04.2
  • Vagrant: 2.2.4
  • Ansible: 2.8.1
  • Virtualbox: 5.2.30

1. Install Vagrant, Ansible and VirtualBox

sudo apt-get install virtualbox vagrant ansible

2. Initiate Vagrant

Create a directory and run the following under it

vagrant box add ubuntu/bionic64
vagrant init ubuntu/bionic64

A file "Vagrantfile" will be created.

"ubuntu/bionic64" refers to Ubuntu 18.04. Vagrant boxes of other OS are listed on https://app.vagrantup.com/boxes/search

3. Append IP address of your host to the end of file /etc/ansible/hosts

alt text

4. Download the zip file from Github and uncompress it. Make sure the uncompressed .yml files and "Vagrantfile" are in the directory you have created in Step 2. "Vagrantfile" should replace the original one created in Step 2

5. Set up the K8S Master Node on the host

First, edit the master-playbook.yml and edit the "vars" values. The attributes are:

  • home_directory
  • cni_provider
  • master_node_ip_address
  • pod_network

Then dry run the master-playbook.yml first and edit the playbook if needed.

ansible-playbook --connection=local master-playbook.yml --check -vvv

If everything seems OK, run

ansible-playbook --connection=local master-playbook.yml

6. Check whether the K8S master node is running

kubectl get nodes

You should see the master node with STATUS "Ready"

7. Set up the K8S Worker Nodes on VirtualBox

Edit the new "Vagrantfile" file created in Step 4 and you may change the properties of the following attributes

  • OS (default: ubunut/bionic64)
  • number of Worker Nodes (default: 3)
  • hostnames
  • vCPU per nodes (default: 2)
  • memory per nodes (default: 2048)
  • IP address range

Then run

vagrant up

8. Done! Now check the status of your K8S environment

kubectl get nodes

alt text

The Kubernetes Dashboard should also be running. On the web browser of the host (i.e., the master node), go to http://localhost:8001/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/

alt text

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published