34
Getting MEAN and Lean with MongoDB and Kubernetes MongoDB World 2016 Vadim Polyakov

MongoDB World 2016: Get MEAN and Lean with MongoDB and Kubernetes

  • Upload
    mongodb

  • View
    373

  • Download
    0

Embed Size (px)

Citation preview

Getting MEAN and Lean with MongoDB and Kubernetes

MongoDB World 2016

Vadim Polyakov

Golden Age of Software Development

{  }Developer

:  )User

DeploymentTesting

www.

Native

About Me Inovalon - R&D, Enterprise Architecture, Software Dev, Healthcare

AOL Advertising - High volume transactions, Big Data

3 Startups – Healthcare and Financial Services

Electrical Engineer – Control Systems

FIRST Robotics Mentor

https://www.linkedin.com/in/vadimpolyakov

Impedance mismatch metaphor

“Lossless” transmission line

Impedance mismatch

Database impedance mismatch Existing concept: Database or Object-relational impedance mismatch

ORM Tools/code (Hibernate, Entity Framework)

Database technology

•  Object Databases

•  Document Databases

Application and database schema are unified

Stack Impedance

Client

HTML,  CSS,  JS

Server

.Net,  Java

Database

SQL

ClientMobile

HTML,  CSS,  JS

Process impedance mismatch

Dev QA UAT Prod

Dev QA UAT Prod

Really tie the stack together Tie together a “thin line architecture” of tools that support agility and developer happiness.

Solve:

•  Stack Impedance

•  Process impedance

9

The stack

Browser(HTML,  JS,  CSS)

ServerREST  API

Data

MEAN - Single Page App

Routable Components [Service, controller, directive]

Routable Components [Middleware]

JSON

Flexible/ComposableFlexible schema Collections

JavaScript/TypeScript

JSON and JS Pipeline

URL

View – HTML template

Controller – Manage the view

Service – Manage the model

URL

Business Logic

Injectable Data Management

MongoDB

Patterns and antipatterns Over-normalizing ⇔ Chatty services

Over-embedding ⇔ Latency

MongoDB

Collection

ProjectExtract

:)

MongoDB

Business  and  Presentation  

Logic

:)

Collection Collection

Just right

MongoDB

Collection

CollectionCollection Collection

Collection

JoinAggregate

:)

Beyond development

Dev QA UAT Prod

Docker

“Docker containers wrap up a piece of software ... This guarantees that it will always run the same, regardless of the environment it is running in.” (https://www.docker.com/what-docker)

Dev QA UAT ProdDev QA UAT Prod

Docker Managed as code – Dockerfile Simple and fast to build images Git-like semantics (push, pull, diff…) Repository of images (public, private)

Management API

Starts in milliseconds (it’s a process)

Application – multiple containers and nodes

nginxnginx content  volumeHTML,  JS,  CSSnginx

Nginx

nginxAPINode

/data/dbvolumenginx

DataMongoDB

Git  Syncnginxnginx content  volumeHTML,  JS,  CSSnginx

Nginx

nginxAPINode

/data/dbvolumenginx

DataMongoDB

Cluster  Config Kubernetes

Git  Sync

Kubernetes Core elements

•  Nodes

•  Pods

•  Replication Controllers

•  Services

Examples:

•  Deploy a MEAN app

•  MongoDB on Kubernetes

Kubernetes Components - Node Node - physical resources

Registers with the master

Resource capacity

Labels

-  tags used to filter the environment e.g. has kernel config for MongoDB

Kubernetes Components - Pod

Pod

-  One or more co-located components with shared context (cgroups, namespaces)

MongoDB  Pod

API  Pod

Web  Pod

nginxnginx content  volumeHTML,  JS,  CSSnginx

Nginx Git  Sync

nginxAPINode

/data/dbvolumenginx

DataMongoDB

nginxnginx content  volumeHTML,  JS,  CSSnginx

Nginx Git  Sync

nginxAPINode

/data/dbvolumenginx

DataMongoDB

Kubernetes Components - Replication Controller

Replication Controller

-  Keep certain number of pod replicas running

Kubernetes Components - Services

Services

-  Set of pods

-  Typically selected using labels

-  Virtual IP

External Services

Headless Service

App deployment Deployment as code svc-www.json rc-www.json svc-app.json rc-app.json svc-arb.json svc-mongo-db1.json svc-mongo-db2.json pod-mongo-db1.json pod-mongo-db2.json rc-arb.json

Web service and replication controller (2 pods)

API service and replication controller (3 pods)

MongoDB services

MongoDB pods and arbiter replication controller

Application up

kubectl create –f ./configdir

Before the demo: •  Start cluster

•  Assign Elastic IP to the cluster

•  Update kubernetes security group to allow port 80

•  Label the nodes

Demo: •  Deploy application

•  Configure replica set

•  Access the web app

•  No ssh deployment

After the demo:

•  Teardown the cluster, run kube-down

Demo Deploy application to a new cluster

Deployment: 1 min

Demo Duration: 12 min

Demo

Deploy application to a new cluster

Deployment: 1 min

Demo Duration: 12 min

•  Recreate production environment for troubleshooting

•  Create any environment for any purpose

•  Blue-green deployment

MongoDB on Kubernetes

“Datacenter as a Computer”

Most nodes in the cluster are “cattle” not “pets”

Some nodes are special

Databases and DB servers are special

•  Kernel config

•  Data is an asset

MongoDB on Kubernetes

Replication Controller?

•  Restart automatically on failure

•  Schedule on multiple nodes

Naked Pods

Services

•  Discoverability

•  Virtual IP

•  DNS

MongoDB on Kubernetes: Demo

MongoDB  Instance

MongoDB  Instance

MongoDB  Arbiter

MongoDB  Instance

MongoDB  Instance

MongoDB  Instance

MongoDB  Arbiter

Replication  Controller

MongoDB  Instance

MongoDB  Instance

MongoDB  Arbiter

Replication  Controller

MongoDB  Instance

Replication  Controller

MongoDB  Instance

MongoDB  Arbiter

Replication  Controller

MongoDB  Instance

Service

MongoDB  Arbiter

Replication  Controller

MongoDB  Instance

MongoDB  Instance

ServiceService

Service

MongoDB  Arbiter

Manual Intervention

Demo Recover from node failure

•  Arbiter migration to healthy node

•  Node recovery

Demo Recover from node failure

•  Arbiter migration to healthy node

•  Node recovery

Demo Recover from node failure

•  Arbiter migration to healthy node

•  Node recovery

Demo Recover from node failure

•  Arbiter migration to healthy node

•  Node recovery

Golden Age •  Aligned application stack – rapid development, eliminate boilerplate

•  Tools like Docker and Kubernetes make deployments and rollbacks safe at any scale

•  Manage all environments as code and reproduce them faithfully whenever I need them – remove process impedance mismatch for setup and troubleshooting

{  }Developer

:  )User

DeploymentTesting

www.

Native

Thank you https://www.linkedin.com/in/vadimpolyakov

https://github.com/polyakov

{  }Developer

:  )User

DeploymentTesting

www.

Native