Image for post
Image for post

Simulating a data center with Kubernetes using virtual machines in your computer

These days I was doing an experiment. I was trying to simulate a phyiscal private cloud environment inside a local computer using virtual machines. Because I needed to setup Kubernetes locally. This experiment has no side effects unlike my previous one 😂 since we are going to use virtual machines only 😎.

Kubernetes

Kubernetes internal architecture is bit complex. Basically it’s a container orchestration system. In earlier time applications were monolithic (Entire app is running on a single server or virtual machine). But nowadays micro-services came over the classical monolithic approach due to critical drawbacks of monolithic systems.

  • No proper load balancing and requests are handled in generic threads in main server
Image for post
Image for post
Kubernetes architecture

Let’s setup VMs

For the virtual machine creation I am going to use Oracle Virtualbox.

Creating Kubernetes master

Kubernetes master is controlling the nodes (can be VMs or physical machines). Let’s go ahead and create 2 machines with Ubuntu server edition iso (No GUI)

Image for post
Image for post
Master and Node VMs in Virtualbox

Adding bridged adapter

For each VM you have to change NAT adapter in to bridged adapter since NAT only allows to browse internet and also outside users can’t directly connect with guest machine. See more

Image for post
Image for post
Network configuration

Mm.. how to setup Kubernetes then (How to make the cluster)

If you used Amazon EKS or Google Kubernetes Engine they setup all the things within minutes. Setting up Kubernetes from scratch is hard. This is where Rancher came to play the game. It makes the cluster creation process easier using Docker containers.

Configuring Kubernetes master

Install and start docker very first

sudo apt-get install docker.io
sudo service docker start
$ sudo docker run -d --restart=unless-stopped -p 8080:8080 rancher/server:stable
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Default -> Manage Environments -> Add Environment

Adding a Kubernetes Node

Kubernetes master is now fine 💪. Let’s add a node. Specially a node can be a physical computer or a virtual machine. Here we are going to use the second virtual machine which was created earlier. Make sure to do the network configuration for this one as well.

sudo apt-get install docker.io
sudo service docker start
Image for post
Image for post

Running a sample microservice

Create a stack very first. Simply stack is a collection of services or load balancers. I am running nginx server for the demonstration purpose.

Image for post
Image for post
Image for post
Image for post

Conclusion

This approach can be used if you need to setup Kubernetes development environment locally. Try adding load balancer and try adding another node even. I am trying to add a Windows node. It looks hard because we will not be able to run hyper-v inside a virtual machine because the virtualbox needs hyper-v disabled. Anyway 😋, We’ll meet in next article.

Written by

Software Engineer at 99x | Apache PMC member | Open Source Contributor (Author of Neutralinojs) | Technical Writer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store