Docker Storage

Daniel Lauzon

2017-01-25

Outline

  • The context
    • scaling containers - stateless vs stateful
    • State of volume drivers
  • The challenge
    • Managing containers requiring persistence
  • The how
    • Demo!

scaling - stateless

solved

Volume drivers

  • local driver

docker run -it --rm -v $(pwd)/data:/data ubuntu

 

What if we are on a swarm?

  • Host-local data might be fine
  • What about databases?

State of volume drivers

The challenge

  • Managing persistence (databases)
  • Adapted to containers
  • Works with multiple hosts
  • Store in Volumes
  • Need Volumes to follow containers
  • Volume lifecycle: provision,delete,...

Resiliency

  • Tolerance to Failure
  • Disaster recovery

Performance

  • Sharding
  • Dynamic rebalancing
  • Auto Scaling...

The How

  • Volume drivers
  • batteries (not quite) included

 

These are the two solutions I got to work:

  • RexRay (libStorage)
  • Kubernetes Persistent Volume claims

RexRay - Swarm

  • docker-machine create, ...
  • docker swarm init, join,join,join
  • install extra software on host
docker volume create -d rexray --name myvolume --opt=size=10

docker volume create -d rexray --name myvolume --opt=size=10 \
  --opt=type=gp2

docker volume create -d rexray --name myvolume --opt=size=10 \
  --opt=type=io1 --opt=iops=150

RexRay - Swarm

# -- create a volume
docker volume create -d rexray --name myvolume --opt=size=10

# -- run and attach from host 1
eval $(docker-machine env node1)
docker run --rm -it --name ubu -v myvolume:/mypath ubuntu
.. do things on myvolume

 

# -- run and attach from host 2
eval $(docker-machine env node2)
docker run --rm -it --name ubu -v myvolume:/mypath ubuntu
.. do things on myvolume

 

RexRay - Swarm

# -- create a volume
docker volume create -d rexray --name myvolume --opt=size=10

# -- service runs container on random host
# --  disk follows container
docker service create --name ubu \
 --mount type=volume,source=myvolume,target=/mypath \
 ubuntu bash -c log-a-message
log-a-message == 
for i in $(seq 1 10); do \ 
  echo $(date -Iseconds) host:$(hostname) Message $i>>/mypath/mylog.txt; 
  sleep 1; 
done

 

 

Kubernetes - PVC

Examples of databases which scale horizontally:

 

  • use kops to provision (aws)
  • ebs driver included
  • Stateful Set
  • Persistent Volume Claims
  • CockroachDB
  • CrateDB

Kubernetes - PVC

kubectl create -f cockroachdb-statefulset.yaml

CockroachDB

  • PostreSQL line compatible
volumeClaimTemplates:
  - metadata:
      name: datadir
      annotations:
        volume.alpha.kubernetes.io/storage-class: anything
    spec:
      accessModes:
        - "ReadWriteOnce"
      resources:
        requests:
          storage: 1Gi

 

Kubernetes - PVC

kubectl run -it --rm generator ...

  • run small load
  • scale up database nodes
  • kill a node
  • generator runs uninterrupted

kubectl scale statefulset cockroachdb --replicas=3

kubectl delete pod cockroachdb-1

Takeaways

Managed Persistence - Volume Drivers

  • Maturing quickly
  • Declarative/Scalable Databases coming!
  • Buyer beware

Thanks

Daniel Lauzon

@daneroo

Docker Storage

By daneroo

Docker Storage

  • 907