The DevOps 2.1 Toolkit

Building, testing, deploying, and monitoring services inside Docker Swarm clusters


Viktor Farcic


@vfarcic

TechnologyConversations.com

CloudBees.com

Viktor Farcic

Docker Containers


  • Portable
  • Low resource usage
  • Scalable
  • Isolation
  • Self-sufficient
  • Immutable

Changed everything


Monoliths

become microservices

Why now?

Changed everything


OS infrastructure

moves to containers

and becomes immutable

Consequences?

Changed everything


Servers

become cluster

The result?

Changed everything


Cluster

changes software architecture

into immutable, stateless services

that communicate through service discovery

The need for new processes!

Changed everything


Agile

changed how we develop software

but it failed to deliver it

It excluded operations!

Changed everything


DevOps

is new agile

It enables teams to be in full control

The result?

Changed everything


DevOps

enables continuous deployment

Changed everything


You are NOT a coder,

a tester, or an operator

You need to know everything

and then specialize

Docker Ecosystem


  • Docker Engine
  • Docker Compose
  • Docker Machine
  • Docker Registry
  • Docker Swarm

Hands-On Time


Setting Up

a Swarm Cluster

and

Running Services

Docker Swarm

Nodes Setup


for i in 1 2 3; do
    docker-machine create -d virtualbox swarm-$i
done

Docker Swarm

Visualizer


eval $(docker-machine env swarm-1)

docker run --name visualizer -d \
    -p 8083:8083 \
    -e HOST=$(docker-machine ip swarm-1) \
    -e PORT=8083 \
    -v /var/run/docker.sock:/var/run/docker.sock \
    dockersamples/visualizer

open http://$(docker-machine ip swarm-1):8083

Provisioning


docker swarm init --advertise-addr $(docker-machine ip swarm-1)

TOKEN=$(docker swarm join-token -q worker)

for i in 2 3; do
    eval $(docker-machine env swarm-$i)

    docker swarm join --token $TOKEN \
        --advertise-addr $(docker-machine ip swarm-$i) \
        $(docker-machine ip swarm-1):2377
done

Cluster Info


eval $(docker-machine env swarm-1)

docker node ls

Cluster Info


Networking


docker network create --driver overlay proxy

docker network create --driver overlay go-demo

docker network ls

Networking


Service


docker service create --name go-demo-db \
    --network go-demo --reserve-memory 100m mongo

docker service ls

docker service create --name go-demo -e DB=go-demo-db \
    --network go-demo --network proxy \
    --reserve-memory 50m vfarcic/go-demo

docker service ps go-demo

docker service inspect go-demo --pretty

Service


Global Service


docker service create --name util \
    --network go-demo --network proxy \
    --mode global alpine sleep 1000000000

docker service ps util

ID=$(docker ps -q --filter label=com.docker.swarm.service.name=util)

docker exec -it $ID apk add --update drill

docker exec -it $ID drill go-demo

docker exec -it $ID drill go-demo-db

Scaling


docker service scale go-demo=5

docker service ps go-demo

Scaling


Failover


docker-machine rm -f swarm-3

docker service ps go-demo

Adding Nodes


docker-machine create -d virtualbox swarm-4

eval $(docker-machine env swarm-4)

docker swarm join --token $TOKEN \
    --advertise-addr $(docker-machine ip swarm-4) \
    $(docker-machine ip swarm-1):2377

eval $(docker-machine env swarm-1)

docker service ps util

Reverse Proxy


wget -O docker-compose-proxy.yml \
    https://raw.githubusercontent.com/vfarcic/docker-flow-proxy/master/docker-compose.yml

export DOCKER_IP=$(docker-machine ip swarm-1)

docker-compose -f docker-compose-proxy.yml up -d consul-server

docker service create --name proxy -p 80:80 -p 443:443 \
    -p 8080:8080 --network proxy -e MODE=swarm --replicas 3 \
    -e CONSUL_ADDRESS=$(docker-machine ip swarm-1):8500 \
    vfarcic/docker-flow-proxy

docker service ps proxy

Reverse Proxy


Reverse Proxy


curl "$(docker-machine ip swarm-1):8080/v1/docker-flow-proxy/reconfigure?serviceName=go-demo&servicePath=/demo&port=8080&distribute=true"

for i in {1..10}; do
    curl -i $(docker-machine ip swarm-1)/demo/hello
done

Networking


Networking


Networking


Networking


Networking


Service Updates


docker service update --image vfarcic/go-demo:1.1 --update-delay 5s go-demo

docker service ps go-demo
"In a time of drastic change, it is the learners who inherit the future. The learned find themselves equipped to live in a world that no longer exists". –Eric Hoffer

Viktor Farcic


@vfarcic


TechnologyConversations.com

Amazon
LeanPub

 
LeanPub

Cleanup

docker-machine rm -f go-demo \
    swarm-1 swarm-2 swarm-4 swarm-test-1 swarm-test-2

rm -rf go-demo docker-compose-proxy.yml