powering microservices with docker, kubernetes, kafka, and mongodb

59
#MDBW17 Andrew Morgan MongoDB Product Marketing POWERING MICROSERVICES WITH DOCKER, KUBERNETES, KAFKA, & MONGODB andrewmorgan

Upload: mongodb

Post on 23-Jan-2018

3.640 views

Category:

Technology


5 download

TRANSCRIPT

Page 1: Powering Microservices with Docker, Kubernetes, Kafka, and MongoDB

#MDBW17

Andrew Morgan – MongoDB Product Marketing

POWERING MICROSERVICES WITH DOCKER, KUBERNETES, KAFKA, & MONGODB

andrewmorgan

Page 2: Powering Microservices with Docker, Kubernetes, Kafka, and MongoDB

#MDBW17

AGENDA

Microservice

s

What, Why,

How?

Containers

Docker, Kafka

Orchestratio

n

Kubernetes,

Mesos, …

MongoDB

Why, How?

When to use Use cases

Who, Why?

1 2 3 4 5 6

Page 3: Powering Microservices with Docker, Kubernetes, Kafka, and MongoDB

MICROSERVICES

Page 4: Powering Microservices with Docker, Kubernetes, Kafka, and MongoDB

#MDBW17

WHY USE MICROSERVICES? (TL;DRWEBSCALE)

Speed Change Maintain Scale Empower

Build MVP quickly Rapid iterations Simple components Product Team == Component

React to market Isolated impact Team Committees

Page 5: Powering Microservices with Docker, Kubernetes, Kafka, and MongoDB

#MDBW17

WHY USE MICROSERVICES? (TL;DRWEBSCALE)

Speed Change Maintain Scale Empower

Build MVP quickly Rapid iterations Simple components Product Team == Component

React to market Isolated impact Team Committees

Page 6: Powering Microservices with Docker, Kubernetes, Kafka, and MongoDB

#MDBW17

WHY USE MICROSERVICES? (TL;DRWEBSCALE)

Speed Change Maintain Scale Empower

Build MVP quickly Rapid iterations Simple components Product Team == Component

React to market Isolated impact Team Committees

Page 7: Powering Microservices with Docker, Kubernetes, Kafka, and MongoDB

#MDBW17

WHY USE MICROSERVICES? (TL;DRWEBSCALE)

Speed Change Maintain Scale Empower

Build MVP quickly Rapid iterations Simple components Product Team == Component

React to market Isolated impact Team Committees

Page 8: Powering Microservices with Docker, Kubernetes, Kafka, and MongoDB

#MDBW17

WHY USE MICROSERVICES? (TL;DRWEBSCALE)

Speed Change Maintain Scale Empower

Build MVP quickly Rapid iterations Simple components Product Team == Component

React to market Isolated impact Team Committees

Page 9: Powering Microservices with Docker, Kubernetes, Kafka, and MongoDB

#MDBW17

WHY USE MICROSERVICES? (TL;DRWEBSCALE)

Speed Change Maintain Scale Empower

Build MVP quickly Rapid iterations Simple components Product Team == Component

React to market Isolated impact Team Committees

Page 10: Powering Microservices with Docker, Kubernetes, Kafka, and MongoDB

#MDBW17

Monolithic

Cross-Team

Tight Coupling

Small Change

Huge Impact

System Retests

Page 11: Powering Microservices with Docker, Kubernetes, Kafka, and MongoDB

#MDBW17

Microservices

Decoupled

Independent Dev

Isolated Impact

Page 12: Powering Microservices with Docker, Kubernetes, Kafka, and MongoDB

#MDBW17

MICROSERVICES EXAMPLE

Twitter

IngestGoogle+

Ingest

Snapcha

t Ingest

Feed

merge

Faceboo

k Ingest

Page 13: Powering Microservices with Docker, Kubernetes, Kafka, and MongoDB

#MDBW17

MICROSERVICES EXAMPLE

Twitter

Ingest

Snapcha

t Ingest

Feed

merge

Faceboo

k Ingest

Page 14: Powering Microservices with Docker, Kubernetes, Kafka, and MongoDB

#MDBW17

MICROSERVICES EXAMPLE

Twitter

Ingest

Snapcha

t Ingest

Feed

merge

Faceboo

k Ingest

Page 15: Powering Microservices with Docker, Kubernetes, Kafka, and MongoDB

#MDBW17

MICROSERVICES EXAMPLE

Twitter

Ingest

Snapcha

t Ingest

Feed

merge

Faceboo

k Ingest

Whatsap

p Ingest

Page 16: Powering Microservices with Docker, Kubernetes, Kafka, and MongoDB

#MDBW17

MICROSERVICES EXAMPLE

Twitter

Ingest

Snapcha

t Ingest

Feed

merge

Faceboo

k Ingest

Whatsap

p Ingest

Snapcha

t IngestSnapcha

t Ingest

Page 17: Powering Microservices with Docker, Kubernetes, Kafka, and MongoDB

#MDBW17

DEVELOPMENT TEAMS

Page 18: Powering Microservices with Docker, Kubernetes, Kafka, and MongoDB

CONTAINERS

Page 19: Powering Microservices with Docker, Kubernetes, Kafka, and MongoDB

#MDBW17

CONTAINERS – POWERING MICROSERVICES

Real world shipping containers

• Road, rail & sea

• Contents untouched

• Ubiquitous & standardized

• Simple

• Contents protected

• Constraints

Page 20: Powering Microservices with Docker, Kubernetes, Kafka, and MongoDB

#MDBW17

CONTAINERS – POWERING MICROSERVICES

Software containers

• 1 image -> Many containers‒ Laptop, DC, cloud

‒ Dev, QA, production, support

• Simple, efficient

• Isolation

• Constraints

Page 21: Powering Microservices with Docker, Kubernetes, Kafka, and MongoDB

#MDBW17

VMS VS. CONTAINERS

VM VMVM

Bare Metal

Host Operating System

Hypervisor

Guest OS

Libraries

Apps

Service

Guest OS

Libraries

Apps

Service

Guest OS

Libraries

Apps

Service

Container ContainerContainer

Bare Metal

Host Operating System

Docker Engine

Libraries

Libraries

Apps

Libraries

Apps

Service ServiceService

Page 22: Powering Microservices with Docker, Kubernetes, Kafka, and MongoDB

#MDBW17

VMS VS. CONTAINERS

VM VMVM

Bare Metal

Host Operating System

Hypervisor

Guest OS

Libraries

Apps

Service

Guest OS

Libraries

Apps

Service

Guest OS

Libraries

Apps

Service

Container ContainerContainer

Bare Metal

Host Operating System

Docker Engine

Libraries

Libraries

Apps

Libraries

Apps

Service ServiceService

Page 23: Powering Microservices with Docker, Kubernetes, Kafka, and MongoDB

#MDBW17

VMS VS. CONTAINERS

VM VMVM

Bare Metal

Host Operating System

Hypervisor

Guest OS

Libraries

Apps

Service

Guest OS

Libraries

Apps

Service

Guest OS

Libraries

Apps

Service

Container ContainerContainer

Bare Metal

Host Operating System

Docker Engine

Libraries

Libraries

Apps

Libraries

Apps

Service ServiceService

Page 24: Powering Microservices with Docker, Kubernetes, Kafka, and MongoDB

#MDBW17

DOCKER

• Simple to use

• 100K+ images on Docker Hub

• Build images from images

• Platforms‒ Linux, OS X, Windows

‒ Laptop, VM, Cloud,…

‒ Cloud services

Page 25: Powering Microservices with Docker, Kubernetes, Kafka, and MongoDB

#MDBW17

RUN MONGODB

docker run -d mongo

Page 26: Powering Microservices with Docker, Kubernetes, Kafka, and MongoDB

#MDBW17

TITLE ONLY

Page 27: Powering Microservices with Docker, Kubernetes, Kafka, and MongoDB

#MDBW17

TITLE ONLY

Page 28: Powering Microservices with Docker, Kubernetes, Kafka, and MongoDB

#MDBW17

MICROSERVICE ARCHITECTURES BUILT ON CONTAINERS

Many small, focused containers ->

sophisticated services

• Well defined APIs

• Independent languages &

libraries

• Modular: easy maintenance +

reuse

• Fault tolerant

• Scalable

Page 29: Powering Microservices with Docker, Kubernetes, Kafka, and MongoDB

#MDBW17

CONNECTING THE MICROSERVICES –KAFKA

Producer

9

8

7

123...

Topic A

Consumer

Page 30: Powering Microservices with Docker, Kubernetes, Kafka, and MongoDB

#MDBW17

CONNECTING THE MICROSERVICES –KAFKA

Producer

9

8

7

123...

Topic A

Consumer

Producer Consumer

Page 31: Powering Microservices with Docker, Kubernetes, Kafka, and MongoDB

#MDBW17

CONNECTING THE MICROSERVICES –KAFKA

Producer

9

8

7

123...

Partition 0

Topic A

Consumer

Producer Consumer

4

3

5

123...

Partition 1

Page 32: Powering Microservices with Docker, Kubernetes, Kafka, and MongoDB

#MDBW17

CONNECTING THE MICROSERVICES –KAFKA

Producer

LEADER

Topic A / Partition 0

Broker 1

FOLLOWER

Topic A / Partition 1

FOLLOWER

Topic A / Partition 0

Broker 2

LEADER

Topic A / Partition 1

Page 33: Powering Microservices with Docker, Kubernetes, Kafka, and MongoDB

#MDBW17

CONNECTING THE MICROSERVICES –KAFKA

Producer

Producer

Producer

9

8

7

123...

Partition 0

4

3

5

123...

Partition 1

7

3

2

123...

Partition N

Topic A

Topic B

7

6

5

123...

Partition 0

New Old

Consumer

Consumer

Page 34: Powering Microservices with Docker, Kubernetes, Kafka, and MongoDB

ORCHESTRATION

Page 35: Powering Microservices with Docker, Kubernetes, Kafka, and MongoDB

#MDBW17

ORCHESTRATION

Automated deployment, connecting, and maintenance of multiple containers

• Provision hosts

• Containers‒ Instantiate

‒ Reschedule

‒ Link

‒ Scale Out/In

• Expose services

Page 36: Powering Microservices with Docker, Kubernetes, Kafka, and MongoDB

#MDBW17

KUBERNETES

Created by Google, feature-rich and widely adopted

• Deployment and ‘replication’

• On-line scale out/in

• Rolling upgrades

• High Availability

• Persistence

• Ports

• Load balancing

• Google Compute Engine

Page 37: Powering Microservices with Docker, Kubernetes, Kafka, and MongoDB

#MDBW17

APACHE MESOS

10,000s of physical servers; used by

Twitter, Airbnb & Apple

• Code (“frameworks) vs.

declarative

• Less feature rich than Kubernetes

• Kubernetes as a Mesos

framework

• Foundation for distributed systems‒ Apache Aurora, Chronos, Marathon

Page 38: Powering Microservices with Docker, Kubernetes, Kafka, and MongoDB

#MDBW17

CHOOSING AN ORCHESTRATION FRAMEWORK

• What you have:‒ Skills?

‒ DevOps frameworks?

‒ Number of hosts?

‒ Bare metal, VMs, or cloud?

• Lifecycle

• Features‒ Automated High Availability?

‒ Grouping and load balancing?

‒ As a service?

Page 39: Powering Microservices with Docker, Kubernetes, Kafka, and MongoDB

MONGODB

Page 40: Powering Microservices with Docker, Kubernetes, Kafka, and MongoDB

#MDBW17

WHY MONGODB IS A GOOD FIT FOR MICROSERVICES

Monitoring

&

Automation

Flexible Data

Model

Redundancy Scalability Simplicity

Page 41: Powering Microservices with Docker, Kubernetes, Kafka, and MongoDB

#MDBW17

WHY MONGODB IS A GOOD FIT FOR MICROSERVICES

Monitoring

&

Automation

Flexible Data

Model

Redundancy Scalability Simplicity

Page 42: Powering Microservices with Docker, Kubernetes, Kafka, and MongoDB

#MDBW17

WHY MONGODB IS A GOOD FIT FOR MICROSERVICES

Monitoring

&

Automation

Flexible Data

Model

Redundancy Scalability Simplicity

Page 43: Powering Microservices with Docker, Kubernetes, Kafka, and MongoDB

#MDBW17

WHY MONGODB IS A GOOD FIT FOR MICROSERVICES

Monitoring

&

Automation

Flexible Data

Model

Redundancy Scalability Simplicity

Page 44: Powering Microservices with Docker, Kubernetes, Kafka, and MongoDB

#MDBW17

WHY MONGODB IS A GOOD FIT FOR MICROSERVICES

Monitoring

&

Automation

Flexible Data

Model

Redundancy Scalability Simplicity

Page 45: Powering Microservices with Docker, Kubernetes, Kafka, and MongoDB

#MDBW17

WHY MONGODB IS A GOOD FIT FOR MICROSERVICES

Monitoring

&

Automation

Flexible Data

Model

Redundancy Scalability Simplicity

Page 46: Powering Microservices with Docker, Kubernetes, Kafka, and MongoDB

#MDBW17

ORCHESTRATING MONGODB USING KUBERNETES

Distributed, stateful application

• Persistent volumes

• External IP addresses for internal

comms

• Init MongoDB replica set

• Monitor

• Backup

Page 47: Powering Microservices with Docker, Kubernetes, Kafka, and MongoDB

Volumename:

mongo-persistent-storage1

pdName: mongodb-disk1

mongodb

-disk1

Containername: mongo-node1

image: mongo

command: mongod –replSet my_replica_set

containerPort: 27017

volumeMounts:

name: mongo-persistent-storage1

mountPath: /data/db

DockerHubRegistry

Podlabels: [name: mongo-node1; instance: rod]

ReplicationControllername: mongo-rc1

labels: [name: mongo-rc]

replicas: 1

selector: [name: mongo-node1]

Service:LoadBalancername: mongo-svc-a

labels: [name: mongo-svc-a]

ports: [port: 27017, targetPort: 27017]]

selector: [name: mongo-node, instance: rod]ExternalIP

Address

104.1.1.1

App

104.1.1.1:27017

Page 48: Powering Microservices with Docker, Kubernetes, Kafka, and MongoDB

ReplicationControlername: mongo-rc-europe

labels: [name: mongo-europe]

replicas: 1

selector: [name: mongo-node]

Volumename:

mongo-persistent-storage

pdName: mongodb-disk-europe

mongodb-

disk-europe

Containername: mongo-node

image: mongo

command: mongod –replSet my_replica_set

containerPort: 27017

volumeMounts:

name: mongo-persistent-storage

mountPath: /data/db

Podlabels: [name: mongo-node]

Service:LoadBalancername: mongo-svc-europe

labels: [name: mongo-svc-europe]

ports: [port: 27017, targetPort: 27017]]

selector: [name: mongo-node]

ReplicationControlername: mongo-rc-asia

labels: [name: mongo-asia]

replicas: 1

selector: [name: mongo-node]

Volumename:

mongo-persistent-storage

pdName: mongodb-disk-asia

mongodb-

disk-asia

Containername: mongo-node

image: mongo

command: mongod –replSet my_replica_set

containerPort: 27017

volumeMounts:

name: mongo-persistent-storage

mountPath: /data/db

Podlabels: [name: mongo-node]

Service:LoadBalancername: mongo-svc-asia

labels: [name: mongo-svc-asia]

ports: [port: 27017, targetPort: 27017]]

selector: [name: mongo-node]

ReplicationControlername: mongo-rc-us

labels: [name: mongo-us]

replicas: 1

selector: [name: mongo-node]

Volumename:

mongo-persistent-storage

pdName: mongodb-disk-us

mongodb-

disk-us

Containername: mongo-node

image: mongo

command: mongod –replSet my_replica_set

containerPort: 27017

volumeMounts:

name: mongo-persistent-storage

mountPath: /data/db

Podlabels: [name: mongo-node]

Service:LoadBalancername: mongo-svc-us

labels: [name: mongo-svc-us]

ports: [port: 27017, targetPort: 27017]]

selector: [name: mongo-node]

Page 49: Powering Microservices with Docker, Kubernetes, Kafka, and MongoDB

#MDBW17

STATEFULSETS

Beta in Kubernetes 1.5/6

• Stable, predictable, unique network identifiers.‒ IP addresses may change

• Stable, persistent storage

• Ordered, graceful deployment and scaling (0 N-1)

• Ordered, graceful deletion and termination (N-1 0)

Page 50: Powering Microservices with Docker, Kubernetes, Kafka, and MongoDB

WHEN TO USE

MICROSERVICES

Page 51: Powering Microservices with Docker, Kubernetes, Kafka, and MongoDB

#MDBW17

WHEN TO USE MICROSERVICES

Page 52: Powering Microservices with Docker, Kubernetes, Kafka, and MongoDB

USE CASES

Page 53: Powering Microservices with Docker, Kubernetes, Kafka, and MongoDB

#MDBW17

MONGODB & MICROSERVICES IN THE WILD

Page 54: Powering Microservices with Docker, Kubernetes, Kafka, and MongoDB

#MDBW17

REFERENCES

• Enabling Microservices – Containers & Orchestration Explained

https://www.mongodb.com/collateral/microservices-containers-and-orchestration-explained

• Microservices: The Evolution of Building Modern Applications

https://www.mongodb.com/collateral/microservices-the-evolution-of-building-modern-

applications

• Data Streaming with Apache Kafka & MongoDB

https://www.mongodb.com/collateral/data-streaming-with-apache-kafka-and-mongodb

Page 55: Powering Microservices with Docker, Kubernetes, Kafka, and MongoDB

#MDBW17

RUNNING MONGODB AS A MICROSERVICE

Page 56: Powering Microservices with Docker, Kubernetes, Kafka, and MongoDB
Page 57: Powering Microservices with Docker, Kubernetes, Kafka, and MongoDB

Conway’s Law1967

Any organization that designs a system will inevitably produce a design whose structure is a copy of the organization's communication structure.”

Page 58: Powering Microservices with Docker, Kubernetes, Kafka, and MongoDB

#MDBW17

ALTERNATE MICROSERVICES EXAMPLE

• Much larger Microservices1. User Account

2. Product Catalog

3. Inventory

4. Orders

• Best practice is each

microservice has its own

database

Page 59: Powering Microservices with Docker, Kubernetes, Kafka, and MongoDB

#MDBW17

SECURITY

Opportunities

• Isolation

• Constrain resources

• Narrow roles

• Keep images/containers current

• root: so restrict access