From one of my previous posts I demonstrated how to provide persistent storage for your containers by using a Convoy NFS Plugin.
I’ve stumbled upon one AWESOME GlusterFS Volume Plugin for Docker by @trajano, please have a look at his repository. I’ve been waiting for some time for one solid glusterfs volume plugin, and it works great.
What we will be doing today
We will setup a 3 node replicated glusterfs volume and show how easy it is to install the volume plugin and then demonstrate how storage from our swarms containers are persisted.
Our servers that we will be using will have the private ip’s as shown below:
1 2 3 |
|
Setup GlusterFS
Have a look at this post to setup the glusterfs volume.
Install the GlusterFS Volume Plugin
Below I’m installing the plugin and setting the alias name as glusterfs
, granting all permissions and keeping the plugin in a disabled state.
1
|
|
Set the glusterfs servers:
1
|
|
Enable the glusterfs plugin:
1
|
|
Create a Service in Docker Swarm
Deploy a sample service on docker swarm with a volume backed by glusterfs. Note that my glusterfs volume is called gfs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
|
Deploy the stack:
1 2 |
|
Have a look on which node is your container running:
1 2 3 |
|
Now jump to the swarm-worker-1
node and verify that the container is running on that node:
1 2 3 |
|
Now since the container is running on this node, we will also see that the volume defined in our task configuration will also be present:
1 2 3 |
|
Exec into the container and look at the disk layout:
1 2 3 4 5 |
|
While you are in the container, write the hostname’s value into a file which is mapped to the glusterfs volume:
1 2 3 |
|
Testing Data Persistence
Time to test the data persistence. Scale the service to 3 replicas, then hop onto a new node where a replica resides and check if the data was persisted.
1 2 3 4 5 6 7 |
|
Check where the containers are running:
1 2 3 4 5 |
|
Hop onto the swarm-worker-2
node and check if the data is persisted from our previous write:
1 2 3 |
|
Now let’s append data to that file, then delete the stack and recreate to test if the data is still persisted:
1 2 3 4 |
|
On the manager delete the stack:
1 2 |
|
The deploy the stack again:
1 2 |
|
Check where the container is running:
1 2 3 |
|
Exec into the container and read the data:
1 2 3 |
|
And as you can see the data is persisted.
Resources
Please have a look and star @trajano’s repository: