Se ha denunciado esta presentación.
Utilizamos tu perfil de LinkedIn y tus datos de actividad para personalizar los anuncios y mostrarte publicidad más relevante. Puedes cambiar tus preferencias de publicidad en cualquier momento.
CREATING HIGHLY-AVAILABLE MONGODB
MICROSERVICES WITH DOCKER
CONTAINERS AND KUBERNETES
Marco Bonezzi
Senior Technical Servi...
About the speaker
I am Marco Bonezzi:
Senior TSE at MongoDB
TSE = Help customers to be successful with MongoDB
Based in Du...
#MDBW17
MICROSERVICES AND CONTAINERS
App
#MDBW17
THERE ARE COMMON PROBLEMS WHEN
USING CONTAINERS:
Capacity
Connectivity
State
Isolation
Affinity
How do we
manage a...
#MDBW17
THIS IS WHAT WE WILL LEARN TODAY
1. Deploy MongoDB on containers using Kubernetes
2. Build a StatefulSet for our M...
#MDBW17
1. MONGODB ON CONTAINERS USING
KUBERNETES
• Why MongoDB is a good fit for microservices:
• Benefits of using Kuber...
#MDBW17
KUBERNETES BUILDING BLOCKS
Node: Provide capacity
o Worker machine for pods (and their containers)
o Virtual or ph...
#MDBW17
Pod: Consume capacity
Group of one or more application containers + shared resources for
those containers
containe...
#MDBW17
Container: Units of packaging
Isolated process. Based on the Linux
kernel:
• Namespaces: what a process can see
• ...
#MDBW17
Service Allow your application to receive traffic
o Logical set of Pods and a policy by which access them
o LabelS...
#MDBW17
BASIC REPLICA SET EXAMPLE
Node
S
P
S
mongod
mongodmongod
https://github.com/kubernetes/minikube
#MDBW17
BASIC REPLICA SET EXAMPLE
https://github.com/sisteming/mongo-kube/tree/master/demo1
#MDBW17
2. BUILDING OUR MONGODB STATEFULSET
• StatefulSet: Designed for applications that require
• Components required:
S...
#MDBW17
STATEFULSET
• Provide a unique identity to its Pods, comprised of an ordinal
Identity stays with the Pod, regardle...
#MDBW17
HEADLESS SERVICE
• Similar to Kubernetes services but without any load balancing
‒ Combined with StatefulSets: uni...
#MDBW17
PERSISTENT STORAGE VOLUMES
• Storage: critical component for Stateful containers
• Dynamic volume provisioning:
Be...
#MDBW17
MONGODB STATEFUL SET
#MDBW17
MONGODB STATEFUL SET
#MDBW17
MONGODB STATEFUL SET
POD - mongo-0
container
(mongod)
POD - mongo-1 POD - mongo-2
SSD
volume
SSD
volume
SSD
volume...
#MDBW17
SUMMARY: WHAT MAKES STATEFUL SETS
GREAT FOR MONGODB
Unique pod identity
Stable network
Stable storage
Scaling
Know...
#MDBW17
DEMO 2: REPLICA SET AS A STATEFULSET
mongo-watch: https://github.com/sisteming/mongo-
kube/tree/master/mongo-watch...
#MDBW17
Node 2Node 1
3. ORCHESTRATING AND DEPLOYING
PRODUCTION-LIKE STATEFULSET
Node 0
rs0
• Replica Sets are about High A...
#MDBW17
• Kubernetes cluster
o Coordinate cluster of computers connected to work as a single unit
o Applications decoupled...
#MDBW17
POD SCHEDULING
• Master controls nodes
(minions) via Scheduler
• Responsible for tracking all
resources and pods
•...
#MDBW17
SCHEDULING OUR REPLICA SET MEMBERS
nodeSelector Node labels Affinity
Eligible if node has
each of the k-v pairs as...
#MDBW17
DISTRIBUTION OVER MULTIPLE NODES
Node 2Node 1Node 0
mongo-0 / rs0 mongo-1 / rs0 mongo-2 / rs0
#MDBW17
COMPUTE RESOURCES FOR CONTAINERS
We can define how much CPU and memory each container needs
CPU
Memory
Requests
Li...
#MDBW17
HIGH AVAILABILITY IN OUR STATEFULSET
Replicated copy of our data
Automatic failover
Scalability of read operations...
#MDBW17
4. MICROSERVICE APPLICATIONS WITH
MONGODB ON KUBERNETES STATEFULSET
Connecting our microservice application (withi...
#MDBW17
DEMO: Q&A LIST
Scenarios:
1. Replica Set failover
2. Pod with primary mongod is
killed
3. Node with primary mongod...
#MDBW17
DEMO 3: MONGODB REPLICA SET
STATEFULSET ON GOOGLE CLOUD ENGINE
https://github.com/sisteming/mongo-kube/tree/master...
#MDBW17
SUMMARY
Key elements for a successful MongoDB Stateful Set on Kubernetes
Resource
requests/limit
s
Persistent
stat...
#MDBW17
THANK YOU!
https://github.com/sisteming/mongo-kube
Creating Highly-Available MongoDB Microservices with Docker Containers and Kubernetes
Próxima SlideShare
Cargando en…5
×

Creating Highly-Available MongoDB Microservices with Docker Containers and Kubernetes

4.474 visualizaciones

Publicado el

Speaker: Marco Bonezzi, Senior Technical Services Engineer, MongoDB
Level: 300 (Advanced)
Track: Microservices

Microservices architectures are becoming more popular and we see a trend towards smaller units of deployment based on containers. While most microservices need databases, implementing MongoDB on containers adds additional complexity: databases are stateful applications where data is critical. MongoDB is a complex distributed system with its own high availability implementation where using containers can expose additional risks.

In this session we will explore how to successfully define our database infrastructure with MongoDB running on Docker containers, how to orchestrate MongoDB containers with Kubernetes in multiple environments, considerations and strategies for managing stateful MongoDB containers, and how to manage high availability and resiliency in a distributed system while running on a container technology such as Kubernetes.

What You Will Learn:
- What to consider and how to maintain stateful databases in containers.
- How to configure deployment files, build a MongoDB deployment, and orchestrate it with Kubernetes, including how to test it on a laptop and then deploy it to Cloud.
- How to handle high availability in this environment, including data and application availability as well the additional error conditions the cloud and microservices introduce.

Publicado en: Tecnología
  • Sé el primero en comentar

Creating Highly-Available MongoDB Microservices with Docker Containers and Kubernetes

  1. 1. CREATING HIGHLY-AVAILABLE MONGODB MICROSERVICES WITH DOCKER CONTAINERS AND KUBERNETES Marco Bonezzi Senior Technical Services Engineer, MongoDB @marcobonezzi marco@mongodb.com
  2. 2. About the speaker I am Marco Bonezzi: Senior TSE at MongoDB TSE = Help customers to be successful with MongoDB Based in Dublin, Ireland Experience in databases, distributed systems, high availability and containers:
  3. 3. #MDBW17 MICROSERVICES AND CONTAINERS App
  4. 4. #MDBW17 THERE ARE COMMON PROBLEMS WHEN USING CONTAINERS: Capacity Connectivity State Isolation Affinity How do we manage all these?
  5. 5. #MDBW17 THIS IS WHAT WE WILL LEARN TODAY 1. Deploy MongoDB on containers using Kubernetes 2. Build a StatefulSet for our MongoDB deployment 3. Production-like recommendations for replica sets on GCE 4. High-Availability considerations for a micro-service application
  6. 6. #MDBW17 1. MONGODB ON CONTAINERS USING KUBERNETES • Why MongoDB is a good fit for microservices: • Benefits of using Kubernetes: Automate the distribution and scheduling of MongoDB containers across a cluster in a more efficient way. Time to market Scalability Resiliency Allignment (API) Flexible Data Model Redundancy Orchestration Persistency Monitoring
  7. 7. #MDBW17 KUBERNETES BUILDING BLOCKS Node: Provide capacity o Worker machine for pods (and their containers) o Virtual or physical o Can be grouped in a cluster, managed by master CPU Memory CPU Memory Pod Pod Pod
  8. 8. #MDBW17 Pod: Consume capacity Group of one or more application containers + shared resources for those containers container container container container Volume Volume Volume IP Image Port … … POD
  9. 9. #MDBW17 Container: Units of packaging Isolated process. Based on the Linux kernel: • Namespaces: what a process can see • cgroups: what a process can use Application + dependencies + shared kernel+ libraries container mongod –dbpath /data/db --port 27017 container
  10. 10. #MDBW17 Service Allow your application to receive traffic o Logical set of Pods and a policy by which access them o LabelSelector to define pods targeted o Types available: ClusterIP, NodePort, LoadBalancer, ExternalName or Headless Service Service B: 10.10.9.3 Service A: 10.10.9.4 POD NODE
  11. 11. #MDBW17 BASIC REPLICA SET EXAMPLE Node S P S mongod mongodmongod https://github.com/kubernetes/minikube
  12. 12. #MDBW17 BASIC REPLICA SET EXAMPLE https://github.com/sisteming/mongo-kube/tree/master/demo1
  13. 13. #MDBW17 2. BUILDING OUR MONGODB STATEFULSET • StatefulSet: Designed for applications that require • Components required: Stable, unique network identifiers mongo-1 mongo-n ... Volu me Volu medata Stable, persistent storage 1 2 3 n Ordered, graceful deployment and scaling Ordered, graceful deletion and terminationPersistent Volume Claim Headless Service StatefulSet
  14. 14. #MDBW17 STATEFULSET • Provide a unique identity to its Pods, comprised of an ordinal Identity stays with the Pod, regardless of which node it is scheduled on Hostnames: Pods created, scaled and deleted sequentially (i.e. mongo-{0..N-1}) mongo-1 mongo-2mongo-0 BETA FEATURE FROM KUBERNETES 1.5
  15. 15. #MDBW17 HEADLESS SERVICE • Similar to Kubernetes services but without any load balancing ‒ Combined with StatefulSets: unique DNS addresses to access pods ‒ Template for DNS name is <pod-name>.<service-name> I’m mongo-1.mongo! Cool, I can add you two to the replica set I’m mongo-2.mongo! rs.initiate() rs.add(“mongo-1.mongo:27017”) rs.add(“mongo-2.mongo:27017”)
  16. 16. #MDBW17 PERSISTENT STORAGE VOLUMES • Storage: critical component for Stateful containers • Dynamic volume provisioning: Before: provision new storage, then create volume in Kubernetes Now: dynamic provision using provisioner defined Persistent Volume Physical Storage Persistent Volume Claim Persistent Volume Persistent Volume Claim POD POD StatefulSet STABLE FROM KUBERNETES 1.6
  17. 17. #MDBW17 MONGODB STATEFUL SET
  18. 18. #MDBW17 MONGODB STATEFUL SET
  19. 19. #MDBW17 MONGODB STATEFUL SET POD - mongo-0 container (mongod) POD - mongo-1 POD - mongo-2 SSD volume SSD volume SSD volume Headless Service (*.mongo, 27017) container (mongod) container (mongod) Application
  20. 20. #MDBW17 SUMMARY: WHAT MAKES STATEFUL SETS GREAT FOR MONGODB Unique pod identity Stable network Stable storage Scaling Known and predictable hostnames Persistency resilient to rescheduling Scale application reads Easier to manage
  21. 21. #MDBW17 DEMO 2: REPLICA SET AS A STATEFULSET mongo-watch: https://github.com/sisteming/mongo- kube/tree/master/mongo-watch https://github.com/sisteming/mongo-kube/tree/master/demo2
  22. 22. #MDBW17 Node 2Node 1 3. ORCHESTRATING AND DEPLOYING PRODUCTION-LIKE STATEFULSET Node 0 rs0 • Replica Sets are about High Availability rs0 rs0 How do we ensure all containers are evenly distributed?
  23. 23. #MDBW17 • Kubernetes cluster o Coordinate cluster of computers connected to work as a single unit o Applications decoupled from individual hosts o Automates the distribution and scheduling of applications containers across a cluster • Two main resources MASTER NODE Kubelet Docker/rkt Schedule applications Maintain state Scaling Rolling updates Worker machine Kubelet: Agent (API) Docker/rkt: Container runtime
  24. 24. #MDBW17 POD SCHEDULING • Master controls nodes (minions) via Scheduler • Responsible for tracking all resources and pods • Takes care of: Resource requirements Constraints Affinity/Anti-affinity
  25. 25. #MDBW17 SCHEDULING OUR REPLICA SET MEMBERS nodeSelector Node labels Affinity Eligible if node has each of the k-v pairs as labels Node 1 mongod-RS1 env: prod rs: rs0 env: prod rs: rs0 env: test rs: rs-t1 mongod-RS1 Hostname os Instance arch Standard set of labels, beta.kubernetes.io Soft/hard constraints on nodes and pods nodeAffinity Affinity or anti- Affinity node labels labels on pods currently running BETA FEATURES IN KUBERNETES 1.6
  26. 26. #MDBW17 DISTRIBUTION OVER MULTIPLE NODES Node 2Node 1Node 0 mongo-0 / rs0 mongo-1 / rs0 mongo-2 / rs0
  27. 27. #MDBW17 COMPUTE RESOURCES FOR CONTAINERS We can define how much CPU and memory each container needs CPU Memory Requests Limits How much I’d like to get (scheduling) The most I can get (contention) CPU Units: spec.containers[].resources.limits.cpu spec.containers[].resources.requests.cpu Bytes: spec.containers[].resources.limits.memory spec.containers[].resources.requests.memory Scheduler Ensures that the sum of the resource requests of the scheduled containers is less than the capacity of the node.
  28. 28. #MDBW17 HIGH AVAILABILITY IN OUR STATEFULSET Replicated copy of our data Automatic failover Scalability of read operations Container restart (same node) Container reschedule (diff. node) Persistent volumes MongoDB Replica Set Kubernetes + Stateful Sets
  29. 29. #MDBW17 4. MICROSERVICE APPLICATIONS WITH MONGODB ON KUBERNETES STATEFULSET Connecting our microservice application (within Kubernetes) mongodb://mongo-0.mongo,mongo-1.mongo,mongo- 2.mongo:27017/APP_? Cases to be handled: o High Availability: 1. Failover (change of primary in the replica set) 2. Pod killed (i.e. Pod is killed and it comes back up) 3. Pod rescheduled (i.e. Node is down and pod gets scheduled to a different node) o Geographically distributed reads: 1. Read from nearest secondary using ReadPreference + Replica Set tags
  30. 30. #MDBW17 DEMO: Q&A LIST Scenarios: 1. Replica Set failover 2. Pod with primary mongod is killed 3. Node with primary mongod is
  31. 31. #MDBW17 DEMO 3: MONGODB REPLICA SET STATEFULSET ON GOOGLE CLOUD ENGINE https://github.com/sisteming/mongo-kube/tree/master/demo3
  32. 32. #MDBW17 SUMMARY Key elements for a successful MongoDB Stateful Set on Kubernetes Resource requests/limit s Persistent state Isolation AffinityScheduling Unique network identifiers High Availability Labels Monitoring Liveness Probes Disruption Budget Further improvements
  33. 33. #MDBW17 THANK YOU! https://github.com/sisteming/mongo-kube

×