Dec 5, 2016

Instaling Ansible on Linux and Mac OS X

Ansible today is the new buzzword in world of DevOps because it allows sysadmins to easily and quickly transform their manual tasks into scripts for automated environment. The best thing about Ansible is that it is easy to learn, is agent less and doesn't require a lot of configuration to make the tool run. 

Apart from being a tool for sysadmins Ansible can be easily learn and put into practice by any developer with the same ease because of its clear syntax, structure and very wide support from open source community. As per Ansible website there are around 2200 contributors out there creating plugins for Ansible, so most probably there's already a solution to the problem or task. 

In this article we will look into installation of Ansible on different OS's and Docker.

Lets begin:

Latest release via YUM:

$ yum install ansible

Latest release via APT(ubuntu)

$ sudo apt-get install software-properties-common
$ sudo apt-add-repository ppa:ansible/ansible
$ sudo apt-get update
$ sudo apt-get install ansible

Latest release via APT (debian)

$ deb http://ppa.launchpad.net/ansible/ansible/ubuntu trusty main
$ apt-get install ansible

Latest release on MAC OS X
$ sudo easy_install pip
$ pip install ansible


Dec 1, 2016

Docker Cheatsheet - Handy Docker commands for everyday use.


Docker is a container management system that helps easily manage Linux Containers. It lets us create images in virtual environments on our laptop or development environments. The actions that we do on containers and its corresponding behaviour remains same when we run them in production environment.


Docker Commands :

$docker --help : It gives full list of all Docker commands.

$docker <COMMAND> --help : To get additional help pertaining for the given command.

$docker version : gives the information about docker installation.

Search Docker Images :

$docker search <search-term> for e.g docker search nginx

Pulling a Docker Image:

$docker pull tutum/ubuntu

List Docker Images :

$docker images

       

Remove Docker Image:

$docker rmi ubuntu:trusty

Run a Docker Image:

$docker run -i -t image_name:tag /bin/bash 
-i gives an interactive shell
-t will assign a pseudo-tty

Run Docker Image as Daemon
<pre>
$docker run -d image_name:tag for e.g. $docker run -d ubuntu:trusty
</pre>
View the running container/s:
$docker ps

Expose the Docker ports in Daemon mode
$docker run -d -p 8080:80 ubuntu:trusty (port 8080 of container is mapped to port 80 of host)

Check the logs of Docker Container
$docker logs container_id or name

Kill a Docker Container:
$docker kill container_id or name

Stop a Docker Container:
$docker stop container_id or name

Get the stats of Docker Container:
$docker stats container_name

$docker top container_name

Remove the container
$docker rm container_name

BUILDING A DOCKER IMAGE
$docker build --help 

$docker build -f path_to_Dockerfile -t REPOSITORY:TAG
REPOSITORY mostly username is used for Docker Hub and <TAG> is the container name.

Building with multiple config files

Create a new directory to hold config files and CD into that directory before executing the build command.

$docker build -t REPOSITORY:TAG


DATA VOLUMES

Mounting a single volume
$docker run -it -v /user/home ubuntu /bin/bash

Mounting multiple volumes 
$docker run -it -v /user/home -v /tmp ubuntu /bin/bash

Mounting local directory inside the Docker Container
$docker run -it -v /user/home:/data ubuntu /bin/bash

Mounting in Read Only mode
$docker run -it -v /user/home:/data:ro ubuntu /bin/bash

We can verify the mounts by issuing :
$docker inspect container_id

DATA VOLUMES CONTAINER










Nov 22, 2016

Beginners Guide to Microservices - Part 1

Today, orgnaization and developers are constantly working towards making applications that scale or are distributed. This constant effort has evolved some very interesting architecture patterns and [Microservices](https://en.wikipedia.org/wiki/Microservices) is one of them. Microservice consists of independent deployable services.

This article focusses on :
    - The Basics.
    - What are micorservices ?
    - Different patterns of microservices. (Part 2)
    - Deployment strategies. (Part 3)
    
    
A bit about terminology used in the article:

    - What is a service ?
    Services in a microservice architecture are processes that communicate with each other over a network in order to fulfill a goal.
    - What is a component ?
    An individual software component is a software package, a web service, a web resource, or a module that encapsulates a set of related functions (or data).
    - What is a container ?
    Docker containers wrap a piece of software in a complete filesystem that contains everything needed to run: code, runtime, system tools, system libraries – anything that can be installed on a server. This guarantees that the software will always run the same, regardless of its environment.
   - Monolithic Application : Any application that is build as a single unit and is also deployed as a single unit i.e if at any point of time a feature is added or bug is fixed then the new version of the application is deployed. Even in load balanced environment the server/vm running application has the full copy of latest code or repo. 

What are Microservices :

Microservices is a terminology for a set of guidelines or architectural pattern which says that each service can be an independent process or constitutes a group of processes. These services are fully independent in terms of development and deployment. Microservices pattern also expects the deployment process to be fully automated. Les illustrate this more with the help of an example :

Developer A is working upon a feature that allows authenticated users to write comments on posts. 
Developer B is working upon a feature that allows authenticated to users write posts.

Monolithic Approach is that both developers are working upon same code repository and pushing their code as per the requirements, features are tested with each deployment and at times regression/sanity testing is also done. With every deployment a new version of code is deployed on server/s and application is again tested just to make sure things are working as expected. A bug in any of the developers code causes the entire application to break apart. This is what stakeholders or users want to experience.

Microservices Approach treats both comments and posts feature as separate services. Both services can share the same database or can have separate database (this will involve a bit of complexity at application level). Each feature works an an independent service without any dependency on each others code. This decoupling helps in deploying each service separately on different virtual instances or containers and in case one of the  service is unavailable, the failure can be handled gracefully and user can still explore other features of web application. 

In this post we have just touched the concept of microservices. I will continue to elaborate this post and wait for my next part in the series.




 References :


  •  http://martinfowler.com/articles/microservices.html#MicroservicesAndSoa
  •  http://microservices.io/index.html