Creating Your Cloud Infrastructure like Google cloud and Digital Ocean from Scratch: Part -3 : FINALLY THE CODING STUFF !!!
Tags: linux, hacktoberfest, javascript, tutorial
Published: 2019-10-22 20:57:56

***Interesting Topic !!! Yeah … Its Part 3 :) The Coding Stuff !!!***

So if you haven’t read my previous posts read Part 1 [here](https://dev.to/manishfoodtechs/creating-your-cloud-infrastructure-like-google-cloud-and-digital-ocean-from-scratch-part-1-3gnm) and Part 2 [here](https://dev.to/manishfoodtechs/creating-your-cloud-infrastructure-like-google-cloud-and-digital-ocean-from-scratch-part-2-5f7f). Do not skip my posts in this series else, you will think at end: ***what we are talking about?***

***A Brief Recap :***

**Part-1:** ***We met cloud brothers and Understand from them who has to use  Hypervisor Type -1 and Hypervisor Type -2 .Why they switched to cloud computing and cloud's various type IaaS, PaaS and SaaS.***  [1](https://dev.to/manishfoodtechs/creating-your-cloud-infrastructure-like-google-cloud-and-digital-ocean-from-scratch-part-1-3gnm).

**Part-2:** ***We again met cloud brothers. Disowned their concept of Cloud computing but called it Advance Virtualization.  Understood, why amazon cloud  people are clever than others. RedHat Inc's difference about cloud and Virtualization. How API (no manual intervention) is creating difference between virtualization & Cloud Computing. Also created a new  Selection criteria among Hypervisor Type -1 types.***  [2](https://dev.to/manishfoodtechs/creating-your-cloud-infrastructure-like-google-cloud-and-digital-ocean-from-scratch-part-2-5f7f).

***Lets continue...***

***To find out your host provider or Machine allows Virtualization Simply run the following command in your Ubuntu Terminal. Use google for your system type.*** 
**command :**`$ lscpu`

![img](https://vitux.com/wp-content/uploads/2018/12/word-image-118.png)


I know my 80 % Readers will fail in above test. ***Do't Worry, I am here.***

Even you don't have Virtualization ready Server or machine , I will let you know how to create a equally good cloud with another hypervisor. 

So, I am going to group the readers of this series into two categories for sake of convenience :

**GROUP -1** : ***Having CPU Virtualization :*** Bare M Server or having personal desktop to playwith .

**GROUP -2** : ***Having No CPU access:*** Those who have Virtual Private Servers. Group 1 readers have advantage to of Group 2 tutorial section. 

You can do code stuff as per your Group Category. 

**CODING PART-1: HYPERVISOR SELECTION**

Last post we have fixed the criteria of choosing among Hypervisors of Type 1 those can create isolated Systems. They are having advantages over Hardware Virtualisers over consumption of less resources.

**GROUP -1** :  ***Hypervisors***: Xen and OpenVZ. The Xen Project hypervisor is the only type-1 hypervisor that is available as open source. Its fueling major cloud Vendors today. Group -1 needs to understand the difference between Xen, XAPI & Xenserver. Its a bit confusing.  Also , we have another trunkey opensource option based on XenServer, [XCP-ng](https://xcp-ng.org/). This is result of massive cooperation between individuals and companies, to deliver a product without limits. No restrictions on features and every bit available on GitHub!Please Watch this video(optional).

{% youtube X1XMc755NjI %}


**GROUP -2** : ***Hypervisors***: You will find that majority of  all clouds developed are based on hardware virtualisers. However, the LXC project by Linux is capable of creating different isolated Linux systems. The advantage is that you only need a linux based OS. Linux Containers (LXC) allow the usage of  technology by creating containers that resemble complete isolated Linux virtual machines on the physical Linux machine, all this by sharing the kernel with the virtual portion of the system.

![img](https://www.opennebula.org/wp-content/uploads/2019/05/hyp2.png)

Amazon, offers application based on containers deployed on virtual machines. 
This means containers are powerful. But when we talk about containers, Docker is another term that comes to everyone. Once , Docker was using LXC but they have now their own library. Futher, LXC / LXD create complete image of OS whereas docker is limited to downloading minimal required ones.

watch this video ... (optional)

{% youtube GYppOyCbM68 %}

**CODING PART-2: UNDERSTANDING THE WHOLE PROCESS OF CLOUD's ARCHITECTURE**

*Remember our definition of cloud from part -2:*

***(Hypervisors + Resource Pooling+ Data Management + bla bla…)+ NO MANUAL INTERVENTIONS*** = CLOUD COMPUTING.
or I can write it as :

**Virtualization + CMP = Cloud**
Here , CPM is Cloud Management Platform.

After mounting of hypervisor(s) , you need a piece of software to automate all your process of creation of Virtual Machines, adding networks , allotting resources and fetching more resources when required. This Piece of software is Cloud Management Platform.  

Cloud services are fighting for market share and are developing the next generation of cloud management systems. Arguably the four biggest players in the market currently are OpenStack, CloudStack, Eucalyptus and OpenNebula. All these are opensource :) . i,e you can use them personally and as well as commercially.

Openstack and cloudstack are with many functionality and are also backed by large number of organisations and developers community. Even, My team also provide support for above two. If you are looking for one , Please drop me a mail: manishfoodtechs@gmailcom.

Before, we really go for some coding stuff, Its worth to watch this video to understand the CMPs ( Cloudstack Vs Openstack):

{% youtube 4qFFwyK9hos %}


**CODING PART-3: LET'S WRITE SOME CODE AND GET OUR FIRST PRODUCTION READY CLOUD**

*YAAA.... COOOOLLLL....*  ***Can't wait???***

I will start with the Group 2 . As this will help both Group 1 and Group 2.

**Group 2 Assets:**
***Machine / server:*** without Kernel access. Like VPS .
***Hypervisor is :*** *LXC* .

If you don't have VPS, then please create a cloud Account by visiting various sites. Create a Droplet with Ubuntu. While, Writing of this post, digital ocean max ubuntu version is 18.04 LTS. Open Console of digital ocean or Putty and get connected as root user.

**The First Command is as usual :** `sudo apt-get update && sudo apt-get upgrade`
Also : `sudo apt-get dist-upgrade`

Our Server is fresh. We need to mount a hypervisor on its OS. Opennebula will do this for you :). Opennebula has very large and detailed documents to go thorugh if we want to download it & build it from source files. you need to be expert in this. I am going to tell a small method that will save your 2-3 days of configuring openebula as new fellow  to cloud architecture.

*** JUST THREE COMMANDS  & YOU WILL HAVE YOUR FIRST CLOUD ***
**Command:**`wget https://github.com/OpenNebula/minione/releases/download/v5.8.1/minione`
**Command:**`sudo chmod u+x minione`
**Command:**`./minione --lxd --force`

 Use Yes ... whenever prompts.

If everything goes good you will get something like this:
OpenNebula 5.8 was installed
Sunstone (the webui) is runninng on:
http://206.189.226.184/
Use following to login:
  user: oneadmin
  password: Tkjjj0Vb8

***troubleshoot***
**E: Sub-process /usr/bin/dpkg returned an error code (1)**
`sudo dpkg --configure -a`
`sudo apt-get install -f`

If the above do not work then try the below command.

`sudo apt-get remove --purge getdeb-repository`

If the above do not work then try the below command.

sudo apt-get remove --purge getdeb-repository

**Command:**`sudo service opennebula-sunstone start` then visit the ip as given in terminal.[ Note: In future if you visit raw IP and you see nothing, please use this command]

Note 206.189.226.184 is my droplet IP and here is my dash board:

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/6lst4a3fw24y4885uu1s.png)


***Good!!!, Now you have your own Cloud Management Software*** Go and use it.
Read docs on there site. If you need any professional help, Please let me know. I will forward it to most concerned Department to help you out. 

Openebula :

1.All Kinds of different images ( ubuntu , centos etc )are available in  Apps Menu.
2.You need to create a VM template and then instance it + naming and a VM is created.
3. If you do not know how to create an VM Template with all fields, don't worry. When open nebula installs by above method it creates a centos VM. Just clone the VM and change the OS next.

4. Making VM to connect with Digital Ocean IP address, so that you can host website etc.

you should add the gateway/DNS information into the virtual network metadata
click on “Network - Virtual Networks”

click on cloud network with ID 0

add new attribute at the bottom, name GATEWAY with value 206.189.226.184 ( my Digital Ocean IP) 

add new attribute, name DNS with value 8.8.8.8

login the sandbox console and run following to enable NAT

`iptables -t nat -A POSTROUTING -o enp0s3 -j MASQUERADE`

If network interface inside the VM is configured with IP assigned by the OpenNebula and default route via 206.189.226.184 , the external services should be working. I tried by pinging 8.8.8.8 and was successful :)


**Group 1 Assets:**
***Machine / server:*** with Kernel access. Like Dedicated Server or computer service.
***Hypervisor is :*** *XEN* .

If You want to download for KVM hypervisor then just run above command of group 1 as:

**Command:**`wget https://github.com/OpenNebula/minione/releases/download/v5.8.1/minione`
**Command:**`sudo chmod u+x minione`
**Command:**`./minione --force
 

Rest is same. 

Xen hypervisor has not been removed from OpenNebula core,
but the driver was moved to the add-on catalog to ease the contributions
and support of the component from the community. Its very easy : [See Github](https://github.com/OpenNebula/addon-xen).


Incase, you need any help let me know. You are most welcome to join my team . You should contact me here [ form details ](https://forms.gle/pSCALuEWHus3pg9F6).

I hope you people like the above series and learned something.

Contact email: Manishfoodtechs@gmail.com. Follow, like or tag me :)