Meet-up event
16th April 2016
@
Pune
Ashish Pandey
Business Consultant &
Tech. Architect (Self Declared)
@ashishapy
blog.ashishapy.com
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
Manager
Node01
Node02
Node03
Docker Hub
Service Discovery
Cluster Manager
Docker Daemon
Discovery Agent
Cluster Agent
Registrator
Application Containers
Registrator
Signup on hub.docker.com
Docker image hosting provider
Re-run commands:
A Dockerfile is a configuration file that contains instructions for building a Docker Image
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
https://www.flickr.com/photos/psd/13109673843/
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
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
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
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.
version: "2"
services:
voting-app:
build: ./voting-app/.
volumes:
- ./voting-app:/app
ports:
- "5000:80"
links:
- redis
networks:
- back-tier
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
Hub
Automated Workflow
Docker
Cloud
Continuous Integration
Continuous Deployment
Microservice
Frontend
Docker Cloud example voting app
Proxy
Database
Microservice
v1
Microservice
v2
OS
a strategy to release new version of the app without downtime
service.mydomain.com
Proxy
Database
Microservice
v1
Microservice
v2
OS
a strategy to release new version of the app without downtime
service.mydomain.com
Service Discovery
Integration / proxy services
Clustering & scaling
Self-healing
Centralised logging & monitoring
For example ...
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
Manager
Node01
Node02
Node03
Docker Hub
Service Discovery
Cluster Manager
Docker Daemon
Discovery Agent
Cluster Agent
Registrator
Application Containers
Registrator
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
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
Building Microservices Cluster
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
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
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/
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/
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
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.)
swarm-microservices-demo
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.
Docker Cloud
Docker Data Center
Doesn't use Swarm
Leverage Labels / tags
Swarm supported
Commercial supported engine
Your thoughts ...
App Development
Docker, DevOps & Microservices
Cloud
Cyber Security
Sometimes IOT