managing microservices with docker

35
© Copyright 2015, Neudesic. All rights reserved. Managing Microservices with Docker Suresh Balla Principal Consultant Neudesic Technologies https://www.linkedin.com/in/sureshballa https:// Open Stack Day – UNICOM July 30 th , 2015

Upload: suresh-balla

Post on 17-Aug-2015

2.025 views

Category:

Software


3 download

TRANSCRIPT

© Copyright 2015, Neudesic. All rights reserved.

Managing Microservices with Docker

Suresh BallaPrincipal Consultant

Neudesic Technologies https://www.linkedin.com/in/sureshballa

https://

Open Stack Day – UNICOMJuly 30th, 2015

© Copyright 2015, Neudesic. All rights reserved. 2

• What are Microservices?

• Why Docker is better virtualization than VMs?

• What is Docker?

• How to manage Microservices with Docker tools?

Agenda

© Copyright 2015, Neudesic. All rights reserved. 3

Monolithic versus Microservices

© Copyright 2015, Neudesic. All rights reserved. 4

Monolithic versus Microservices

http://martinfowler.com/articles/microservices.html

© Copyright 2015, Neudesic. All rights reserved. 5

Characteristics of a Microservices Architecture

• Componentization via Services• Organized around Business Capabilities -

Conway's Law• Products not Projects• Decentralized Governance• Design for failure• Enable autonomous team

• Scales development – develop, deploy and scale each service independently

• Improves fault isolation• Eliminate long term commitment to a single

technology stack - Easily try other technologies and fail safe• Clojure, nodejs, scala, akka, spray,

spring boot, play etc.

© Copyright 2015, Neudesic. All rights reserved. 6

Who are using Microservices

© Copyright 2015, Neudesic. All rights reserved. 7

Microservices on VMs

Hardware

Operating System

Type 2 Hypervisor

Virtual Machine

Operating System

Bins / libs

S5 S6

Virtual Machine

Operating System

Bins / libs

S7 S8

Hardware

Type 1 Hypervisor

Virtual Machine

Operating System

Bins / libs

S1 S2

Virtual Machine

Operating System

Bins / libs

S3 S4

© Copyright 2015, Neudesic. All rights reserved. 8

How about this solution?

Hardware

Operating System

Container

Bins / libs

App App

Container

Bins / libs

App App

Hardware

Operating System

Container

Bins / libs

S1 S2

Container

Bins / libs

S3 S4

Hardware

Operating System

Container

Bins / libs

App App

Container

Bins / libs

App App

Hardware

Operating System

?

Bins / libs

S1 S2

?

Bins / libs

S3 S4

© Copyright 2015, Neudesic. All rights reserved. 9

Welcome to Docker - The raise of container technologies

© Copyright 2015, Neudesic. All rights reserved. 10

What is Docker?

Static website

Web frontend

User DB

Queue Analytics DB

Background workers

API endpoint

nginx 1.5 + modsecurity + openssl + bootstrap 2

postgresql + pgv8 + v8

hadoop + hive + thrift + OpenJDK

Ruby + Rails + sass + Unicorn

Redis + redis-sentinel

Python 3.0 + celery + pyredis + libcurl + ffmpeg + libopencv + nodejs + phantomjs

Python 2.7 + Flask + pyredis + celery + psycopg + postgresql-client

Development VM

QA server

Public Cloud

Disaster recovery

Contributor’s laptop

Production Servers

The ChallengeM

ultip

licity

of

Stac

ks

Mul

tiplic

ity o

f ha

rdw

are

envi

ronm

ents

Production Cluster

Customer Data Center

Do services and apps interact

appropriately?

Can I migrate

smoothly and quickly?

Slide Reference: DockerCon

Static website Web frontend User DB Queue Analytics DB

Development VM

QA server Public Cloud Contributor’s laptop

Or…put more simplyM

ultip

licity

of S

tack

sM

ultip

licity

of

hard

war

e en

viro

nmen

ts

Production Cluster

Customer Data Center

Do services and apps interact

appropriately?

Can I migrate

smoothly and quickly

Operator: Configure Once, Run Anything

Developer: Build Once, Run Anywhere (Finally)

Slide Reference: DockerCon

© Copyright 2015, Neudesic. All rights reserved. 13

A useful analogy

Mul

tiplic

ity o

f G

oods

Mul

tipili

city

of

met

hods

for

tran

spor

ting/

stor

ing

Do I w

orry about how

goods interact (e.g. coffee beans

next to spices)

Can I transport quickly and sm

oothly(e.g. from

boat to train to truck)

Cargo Transport Pre-1960

Slide Reference: DockerCon

Mul

tiplic

ity o

f G

oods

Mul

tiplic

ity o

f m

etho

ds fo

r tr

ansp

ortin

g/st

orin

g

Do I w

orry about how

goods interact (e.g. coffee beans

next to spices)

Can I transport quickly and sm

oothly(e.g. from

boat to train to truck)

Solution: Intermodal Shipping Container

…in between, can be loaded and unloaded, stacked, transported efficiently over long distances, and transferred from one mode of transport to another

A standard container that is loaded with virtually any goods, and stays sealed until it reaches final delivery.

Slide Reference: DockerCon

© Copyright 2015, Neudesic. All rights reserved. 16

VMs vs Bare Containers vs Docker

Hardware

Operating System

Type 2 Hypervisor

Virtual Machine

Operating System

Bins / libs

App App

Virtual Machine

Operating System

Bins / libs

App App

Hardware

Type 1 Hypervisor

Virtual Machine

Operating System

Bins / libs

App App

Virtual Machine

Operating System

Bins / libs

App App

Hardware

Operating System

ContainerBins / libs

App App

Container

Bins / libs

App App

© Copyright 2015, Neudesic. All rights reserved. 17

Docker Architecture

• Client Server Architecture• Sockets or RESTfull API

• Docker Daemon• Docker client• Images – a read-only

templates• Registries - holds images• Container – created from

an image

© Copyright 2015, Neudesic. All rights reserved. 18

Docker Workflow

Source Code Repository

Dockerfile

Docker Engine

Docker

Container

Image Registry

Build

Do

cker

Host 2 OS (Linux)

Container A

Container B

Container C

Container A

Push

Search Pull

Run

Host 1 OS (Linux)

Slide Reference: DockerCon

© Copyright 2015, Neudesic. All rights reserved. 19

• Pulls the base ubuntu image• Creates a new container• Allocates a filesystem and mounts a read-write layer• Allocates a network / bridge interface• Sets up an IP address• Executes a process that you specify• Captures and provides application output

sudo docker run -i -t ubuntu /bin/bash

© Copyright 2015, Neudesic. All rights reserved. 20

• docker search• docker pull• docker run• docker commit• docker inspect• docker push• docker images

Docker CLI

© Copyright 2015, Neudesic. All rights reserved. 21

• On your servers (LINUX)• Packages (Ubuntu, Debian, Fedora etc.)• Single Binary install • Easy provisioning on Rackspace, Digital Ocean, AWS – EC2,

GCE, Windows Azure• On your dev environment

• Docker Machine• Vagrant Up• Boot2docker (25 MB VM image)• Natively (If you run Linux)

Setup

Linux Kernel 3.10

© Copyright 2015, Neudesic. All rights reserved. 22

Authoring Images with Dockerfile# DOCKER-VERSION 0.10.0

# Pull base image.FROM ubuntu:14.04

# Install Node.jsRUN apt-get updateRUN apt-get install -y software-properties-commonRUN add-apt-repository -y ppa:chris-lea/node.jsRUN apt-get updateRUN apt-get install -y nodejsRUN apt-get install -y supervisorRUN mkdir -p /var/log/supervisor

ADD . /src

# add the supervisor config file to default location that it would look forADD supervisord.conf /etc/supervisor/conf.d/supervisord.conf

RUN cd /src; npm install

ENV PORT 3001ENV NODE_ENV development

EXPOSE 3001

CMD ["node", "/src/server.js"]

© Copyright 2015, Neudesic. All rights reserved. 23

Demo

© Copyright 2015, Neudesic. All rights reserved. 24

Docker Hub

http://blog.docker.com/2014/06/announcing-docker-hub-and-official-repositories/

25

Docker Ecosystem

https://twitter.com/docker/status/476030821392867328

© Copyright 2015, Neudesic. All rights reserved.

Docker Platform - Includes batteries but replaceable

Machine Compose

Swarm

Core

© Copyright 2015, Neudesic. All rights reserved. 27

Drivers exists for:• SoftLayer• AWS• DigitalOcean• Azure• Google Compute Engine• Rackspace• OpenStack• Virtualbox• VMWare Fusion• VMWare vSphere• Hyperv

Docker machine

© Copyright 2015, Neudesic. All rights reserved. 28

Docker compose

Define and run multi-container application

© Copyright 2015, Neudesic. All rights reserved. 29

docker-compose.yml

© Copyright 2015, Neudesic. All rights reserved. 30

Demo

nginx

nodejs nodejs nodejs

redis

© Copyright 2015, Neudesic. All rights reserved. 31

Docker Swarm

Native clustering tool for Docker

© Copyright 2015, Neudesic. All rights reserved. 32

• Ranking strategy• spread• binpack• Random

Docker Swarm – Schedule Strategies and Filters

• Filters• Constraint• Affinity• Port• Dependency• Health

© Copyright 2015, Neudesic. All rights reserved. 33

Demo

node2

192.168.33.12

node3

192.168.33.13Swarm-manager

192.168.33.11

© Copyright 2015, Neudesic. All rights reserved. 34

The BIG PICTURE

Accounting Service code

Inventory Service code

ShippingService code

UtilityService code

java image

mongoimage

nginximage

shippingimage

Accounting Container

InventoryContainer

ShippingContainer

SecurityContainer

API GatewayContainer

ServiceContainer

InventoryContainer

ShippingContainer

Accounting Container

Github or any Git repo

Docker Hub or Private Registry

Servers

Git clone repository

Pull Docker images

Build Docker images

Compose or Swarm

Build images or pull images and create containers

Docker Machine

Jenkins CI

Create machines using different drivers of Machine

© Copyright 2015, Neudesic. All rights reserved.

THANK YOU