Docker Ecosystem for Microservices
Meet-up event
16th April 2016
@
Pune
Ashish Pandey
Business Consultant &
Tech. Architect (Self Declared)
@ashishapy
blog.ashishapy.com
Preview
Node
Host Machine
Voting App
Cluster Orchestrator
Deploy Services
Cluster
Health Monitor
Registrator
Service Registry
Data Collector
Historical Data
Corrective Action
Monitors services
Sends service info
Observes desired state
Collect data
Stores data
Observes tendencies
Invoke corrective action
Reference Architecture for Cluster
Manager
Node01
Node02
Node03
Docker Hub
Service Discovery
Cluster Manager
Docker Daemon
Discovery Agent
Cluster Agent
Registrator
Application Containers
Registrator
Virtual Machines vs Containers
Get Started
-
Install Docker Engine on host machine
- Windows or Mac: Docker toolbox
- For quick start use my Digital Ocean referral: https://m.do.co/c/af7efed41ac1 . You will get $10 credit, more than enough for the exercise.
Docker hub
Signup on hub.docker.com
Docker image hosting provider
Docker Containers
- Run container from a image: docker run
- Check running containers: docker ps
- Check all (Running, Stopped, Paused) containers: docker ps -a
- Inspect a container: docker inspect
Docker’s architecture
Run a software image in a container
- docker run hello-world
- docker run -i -t ubuntu /bin/bash
Re-run commands:
- docker info
- docker images
- docker ps
- docker ps -a
- docker history <ImageId>
Dockerfile
A Dockerfile is a configuration file that contains instructions for building a Docker Image
Demo Node Web App
Microservices
Services are small - fine-grained to perform a single function.
Services are easy to replace and deploy independently
One service fails, then the whole application does not have to fail
Services can be implemented using different programming languages, databases, hardware and software environment, depending on what fits best
Service
One service managed by two pizza team
Comes with complexity and new challenges
Microservices ...
https://www.flickr.com/photos/psd/13109673843/
Principles of Microservices
Microservices
Modeled around business concept
Small autonomous services
Culture of automation
Highly Observable
Isolate failure
Deploy independently
Decentralize all the things
Hide internal implementation details
Cultural change is the key
Frontend
for Microservices
Microservice
Presentation
Frontend-Integration
Microservice
Microservice
Microservice
Microservice
Microservice
Microservice
Monolithic
Microservice
Presentation
Frontend-Integration
Microservice
Microservice
Microservice
Microservice
Microservice
Microservice
vs
Monolithic
Frontend Router
Microservice
Frontend
Microservice
Frontend
Microservice
Frontend
Microservice
Frontend
Microservice
Read more here
Microservice
Frontend
Example Voting App
All containers are not necessary to be on same host machine
That means... 1. Multi-container app & 2. Containers, lots of containers
10:30
That means containers, lots of container and containers every where
That is 'Cluster of Containers'
Cluster
All containers are not necessary to be on same host machine
10:25
Demo
Multi-container App
Multi-container App
docker-compose is a tool for defining and running multi-container Docker applications. Few common use cases.
Compose is still primarily aimed at development and testing environments. Compose may be used for smaller production deployments, but is probably not yet suitable for larger deployments.
Docker Compose
- Install docker-compose
- Create docker-compose.yml
version: "2"
services:
voting-app:
build: ./voting-app/.
volumes:
- ./voting-app:/app
ports:
- "5000:80"
links:
- redis
networks:
- back-tier
Creating Multi-container App
-
Define your app’s environment with a Dockerfile so it can be reproduced anywhere.
-
Define the services that make up your app in docker-compose.yml so they can be run together in an isolated environment.
-
Lastly, run docker-compose up and Compose will start and run your entire app.
Demo: example-voting-app
DevOps (CI/CD) Workflow
Hub
Automated Workflow
Docker
Cloud
Continuous Integration
Continuous Deployment
Ok! Automated Workflow!
But how does it help in building Microservices?
Microservice
Frontend
Docker Cloud example voting app
Blue-Green Deployment
Proxy
Database
Microservice
v1
Microservice
v2
OS
a strategy to release new version of the app without downtime
service.mydomain.com
Blue-Green Deployment...
Proxy
Database
Microservice
v1
Microservice
v2
OS
a strategy to release new version of the app without downtime
service.mydomain.com
There are still a lot of things to talk about...
-
Service Discovery
-
Integration / proxy services
-
Clustering & scaling
-
Self-healing
-
Centralised logging & monitoring
For example ...
Enough of talking around...
Let's jump to see 10,000ft view of Self-healing Microservices system
Cluster Orchestrator
Deploy Services
Cluster
Health Monitor
Registrator
Service Registry
Data Collector
Historical Data
Corrective Action
Monitors services
Sends service info
Observes desired state
Collect data
Stores data
Observes tendencies
Invoke corrective action
Cluster Orchestrator
Deploy Services
Cluster
Health Monitor
Registrator
Service Registry
Corrective Action
Monitors services
Sends service info
Observes desired state
Invoke corrective action
Consul
Consul Watches
Jenkins
Docker Swarm
One of the combinations of tools
Reference Architecture
Manager
Node01
Node02
Node03
Docker Hub
Service Discovery
Cluster Manager
Docker Daemon
Discovery Agent
Cluster Agent
Registrator
Application Containers
Registrator
Service Discovery - Consul
Datacenter 1
Datacenter 2
Client
Client
Client
Server
Server (Leader)
Server
Server
Server
(Leader)
Server
Internet
TCP & UDP 8301
TCP & UDP 8301
TCP 8300
RPC
TCP 8300
RPC
TCP & UDP 8301
LAN Gossip
Replication
TCP 8300
Replication
TCP 8300
TCP & UDP 8302
WAN Gossip
TCP 8300
TCP 8300
Remote DC Forwarding
Replication
TCP 8300
Replication
TCP 8300
TCP & UDP 8302
Leader Forwarding
Leader Forwarding
Gossip Protocol
Service registry bridge for Docker
Registrator automatically registers and deregisters services for any Docker container by inspecting containers as they come online.
docker run -d \
--name=registrator \
--net=host \
--volume=/var/run/docker.sock:/tmp/docker.sock \
gliderlabs/registrator:latest \
consul://<consulAddr>:8500
Cluster
Docker Native Clustering - Swarm
Turn a group of Docker engines into a single, virtual Docker Engine
Service Discovery
Get latest cluster config & state
Node
Node
Node
Node
Node
Node
Node
Node
Node
Node
Node
Node
Node
Node
Node
Node
Node
Node
Node
Node
Node
Node
Node
Node
Node
Node
Node
Node
Node
Node
Node
Node
Node
Node
Node
Node
Node
Node
Node
Node
Node
Node
Node
Node
Node
Node
Node
Node
Node
Node
Node
Node
Node
Node
Demo
Building Microservices Cluster
Things to do for Demo
-
We need infrastructure (physical servers / virtual machines).
-
Create logical collection i.e. make cluster.
-
Test / verify if cluster is acting as single view.
-
Deploy your app.
not part of demo
Understanding Docker command
docker -H=tcp://192.168.33.11:2375 run \
--restart=unless-stopped -d -p 3375:2375 \
-h swarmgr --name swarmgr -v /mnt:/data \
Container host name
detach mode
Docker Daemon socket(s) to connect to
Container name
host:container
Bind mount a volume
port mapping
host:container
swarm manage consul://192.168.33.11:8500
Image repo name
Command
Commands
Build the Discovery Service Server: docker -H=tcp://192.168.33.11:2375 run --restart=unless-stopped -d -h consul --name consul -v /mnt:/data \ -p 192.168.33.11:8300:8300 \ -p 192.168.33.11:8301:8301 \ -p 192.168.33.11:8301:8301/udp \ -p 192.168.33.11:8302:8302 \ -p 192.168.33.11:8302:8302/udp \ -p 192.168.33.11:8400:8400 \ -p 192.168.33.11:8500:8500 \ -p 172.17.0.1:53:53/udp \ progrium/consul -server -advertise 192.168.33.11 -bootstrap
Build Swarm Managers:
docker -H=tcp://192.168.33.11:2375 run --restart=unless-stopped -d -p 3375:2375 --name swarmgr \
swarm manage consul://192.168.33.11:8500/
Build Registrator:
docker -H=tcp://192.168.33.11:2375 run -d --name registrator -h registrator \
-v /var/run/docker.sock:/tmp/docker.sock \
gliderlabs/registrator consul://192.168.33.11:8500/
Commands ...
Build the Discovery Service Agent:
docker -H=tcp://192.168.33.20:2375 run --restart=unless-stopped -d -h consul-agt1 --name consul-agt1 -v /mnt:/data \
-p 8300:8300 \
-p 8301:8301 -p 8301:8301/udp \
-p 8302:8302 -p 8302:8302/udp \
-p 8400:8400 \
-p 8500:8500 \
-p 8600:8600/udp \
progrium/consul -rejoin -advertise 192.168.33.20 -join 192.168.33.11
Build Swarm agent:
docker -H=tcp://192.168.33.20:2375 run -d swarm join \
--advertise=192.168.33.20:2375 consul://192.168.33.20:8500/
Build Registrator:
docker -H=tcp://192.168.33.20:2375 run -d --name registrator -h registrator \
-v /var/run/docker.sock:/tmp/docker.sock gliderlabs/registrator:latest \
consul://192.168.33.20:8500/
Docker Swarm - Scheduling
Filters
Strategies
-
Node filter
-
Constraint
-
Health
-
-
Container config filter
-
Affinity
-
Dependency
-
Port
-
-
Spread (default)
-
Binpack
-
Random
Ranking nodes & pick the best
Which nodes to use
$ docker tcp://<manager_ip:manager_port> run -d --name redis1 -e affinity:image==~redis redis
There are still many problems with demo
-
Cluster is not talking over secure network
-
Managers are single point failure
-
Containers deployment are not controlled
-
Docker Swarm filtering & scheduling
-
-
Manual configuration of infrastructure and cluster
-
Use configuration management tools (Ansible, Chef, Puppet etc.)
-
Try this at your pace, later...
swarm-microservices-demo
A curated list of tools
Type |
Tools |
---|---|
Configuration Management |
CFEngine, Puppet, Chef, Ansible |
Service Discovery |
Zookeeper, etcd, Consul |
Proxy Services |
HAProxy, Nginx |
Continuous Integration (CI) / Continuous Delivery, Deployment (CD) |
Travis, Shippable, CircleCI, Drone.io |
Clustering / Scaling |
Kubernetes, Mesos, Swarm |
Logging & Monitoring |
ElasticSearch + LogStash + Kibana (ELK) |
It's a quest to deploy often and fast, be fully automatic, accomplish zero-downtime, have the ability to rollback, provide constant reliability across environments, be able to scale effortlessly, and create self-healing systems able to recuperate from failures.
Commercial offerings from Docker
Docker Cloud
Docker Data Center
Doesn't use Swarm
Leverage Labels / tags
Swarm supported
Commercial supported engine
Your thoughts ...
What I am doing now or next
-
App Development
-
Docker, DevOps & Microservices
Cloud
-
Cyber Security
-
Sometimes IOT
Docker & Microservices
By Ashish Pandey
Docker & Microservices
Service Discovery, Clustering And Scaling in Microservices
- 2,215