Skip to content

Small dev-ops project using Vagrant to provision virtual machines, Ansible playbooks to install software, and Docker, Docker Compose, and Docker Swarm to control.

Notifications You must be signed in to change notification settings

Kasdal/Dev-ops-practice

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

59 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Microservices Dev-Ops Project.

Simple python project using multiple VM machines to create a microservices for basic app.


Table of Contents

General Information

  • Fairly simple take on microservices running on multiple machines.
  • Main purpose is to learn more and familiarize one self with the possibilities of infrastructure as code.

Technologies Used

  • Git
  • Vagrant
  • Virtual Box, Vmware or other
  • Ansible
  • Docker
  • Docker Compose
  • Docker Swarm

Features

List the ready features here:

  • Infrastructure as code ready to deploy
  • Automated software instalation
  • Containerization
  • Orchestration

✅ Step-by-step Instructions

Download the project to your local machine and open it in VSCode, PowerShell or some other IDE. Open a terminal in VSCode


Start by running the following commands
"Vagrant init" 

to initialise the provisioning of virtual machines.

"Vagrant up"

to start your machines

Vagrant ssh main 

to access the main host. If it asks for password, password=Vagrant

Go into your vagrant folder and do

sudo cp host /etc/hosts

to copy over the the information contained in your local host file to your machine. Try to ping your machine

ping server1

you should be able to get a response.

While still in "main" machine do

ssh-keygen

while creating ssh key leave it without the password. Once the key is created you will need to copy it to other 3 servers.

ssh-copy-id server1 && ssh-copy-id server2 && ssh-copy-id server3

this will copy over the public key from main. Once copied, test that you have ssh access to servers.

ssh vagrant@server1

it should connect to it without asking for password.

Now we can install and test our ansible capabilites

sudo apt install ansible

change directory to ansible

cd ansible

run

ansible servers -i thehosts -m command -a hostname

You should get a response that it found "main" and get all 3 responses from servers

img1

If all of the tests passed, let's now have some fun and explore the power of ansible.

run

ansible servers -i thehosts -m command -a 'sudo apt-get -y install python-simplejson

Which will install python and json on all our servers allowing us to have more capabilities on those machines.

img2

Ok so, let's run our ansible playbook and install docker on all 3 servers. Running the following command on your "main" will do just that.

ansible-playbook -i thehosts -K playbook1.yaml

img4

After we can run a quick script to make sure docker was properly installed. Ssh into all servers and run

docker run hello-world

Next we can fork this project https://github.com/nextrevision/ansible-swarm-playbook to get docker swarm on our system. You will need to adjust couple of things to make it work, mainly the host inventory file and add a manager and worker node to it. Also required is to change eth0 interface in swarm.yaml to eth1

ansible-swarm

Now we can go to one of the servers and verify that the cluster is created.

swarm-rdy

With all that done we can now run

docker-stack deploy -- compose-file docker compose yaml myapp

Once the service is compiled you can check it's status

docker service ps myapp_web

Next, let's now scale our application which is the main goal of this exercise. Run

docker service scale myapp_web=10

this will scale our app to 10 containers spread over all 3 servers. And you can easily scale this up to 1000+ provided that your machines can hadle the load.

End

Now go open another PowerShell, Terminal etc.. and ssh into main,

cd /vagrant/ansible

and test that your services are actually running in multiple containers. You can run curl server1:5000 or any other server and you can see that every time you run that command you will likely get a response from a container with different id.

Test1


You can adapt this project to run any other app by editing Dockerfile with your variation, make changes to requirements.txt, and docker-compose.yaml You can then use the Dockerfile to build the image and host it on Dockerhub or similar service.

Enjoy!

Project Status

Project is: mostly done.

Room for Improvement

Room for improvement:

  • Add monitoring by implementing Grafana, Prometheous or similar.

About

Small dev-ops project using Vagrant to provision virtual machines, Ansible playbooks to install software, and Docker, Docker Compose, and Docker Swarm to control.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published