Skip to content

Vagrantfile & Scripts to setup Kubernetes Cluster using Kubeadm

License

Notifications You must be signed in to change notification settings

renatowow14/Kubernetes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Setup Prerequisites

  • A working Vagrant setup using Vagrant + VirtualBox

Here is the high level workflow.

Documentation

The setup is updated with 1.31 cluster version.

Prerequisites

  1. Have kubectl installed on your machine
  2. Run script init.sh to install Vagrant and Virtualbox 7.0 Version
  3. Install vagrant-vbguest plugin vagrant plugin install vagrant-vbguest
sudo mkdir -p /etc/vbox
echo "* 10.0.0.0/8" | sudo tee -a /etc/vbox/networks.conf
echo "* 192.168.56.0/21" | sudo tee -a /etc/vbox/networks.conf
sudo systemctl restart vboxdrv
cd Kubernetes && vagrant up
  1. Working Vagrant setup
  2. 8 Gig + RAM workstation as the Vms use 3 vCPUS and 4+ GB RAM

So that the host only networks can be in any range, not just 192.168.56.0/21 as described here: https://discuss.hashicorp.com/t/vagrant-2-2-18-osx-11-6-cannot-create-private-network/30984/23

Bring Up the Cluster

To provision the cluster, execute the following commands.

git clone https://github.com/renatowow14/Kubernetes.git
cd Kubernetes
vagrant up

Set Kubeconfig file variable

cd Kubernetes
cd configs
export KUBECONFIG=$(pwd)/config

or you can copy the config file to .kube directory.

cp config ~/.kube/

Install Kubernetes Dashboard

The dashboard is automatically installed by default, but it can be skipped by commenting out the dashboard version in settings.yaml before running vagrant up.

If you skip the dashboard installation, you can deploy it later by enabling it in settings.yaml and running the following:

vagrant ssh -c "/vagrant/scripts/dashboard.sh" controlplane

Kubernetes Dashboard Access

To get the login token, copy it from config/token or run the following command:

kubectl -n kubernetes-dashboard get secret/admin-user -o go-template="{{.data.token | base64decode}}"

Make the dashboard accessible:

kubectl proxy

Open the site in your browser:

http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/#/login

To shutdown the cluster,

vagrant halt

To restart the cluster,

vagrant up

To destroy the cluster,

vagrant destroy -f

Network graph

                  +-------------------+
                  |    External       |
                  |  Network/Internet |
                  +-------------------+
                           |
                           |
             +-------------+--------------+
             |        Host Machine        |
             |     (Internet Connection)  |
             +-------------+--------------+
                           |
                           | NAT
             +-------------+--------------+
             |    K8s-NATNetwork          |
             |    192.168.99.0/24         |
             +-------------+--------------+
                           |
                           |
             +-------------+--------------+
             |     k8s-Switch (Internal)  |
             |       192.168.99.1/24      |
             +-------------+--------------+
                  |        |        |
                  |        |        |
          +-------+--+ +---+----+ +-+-------+
          |  Master  | | Worker | | Worker  |
          |   Node   | | Node 1 | | Node 2  |
          |192.168.99| |192.168.| |192.168. |
          |   .99    | | 99.81  | | 99.82   |
          +----------+ +--------+ +---------+

This network graph shows:

  1. The host machine connected to the external network/internet.
  2. The NAT network (K8s-NATNetwork) providing a bridge between the internal network and the external network.
  3. The internal Hyper-V switch (k8s-Switch) connecting all the Kubernetes nodes.
  4. The master node and two worker nodes, each with their specific IP addresses, all connected to the internal switch.

About

Vagrantfile & Scripts to setup Kubernetes Cluster using Kubeadm

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages