8

How to Implement Docker Swarm with PostgreSQL and Web-Services on Nutanix ACS Sh...

 3 years ago
source link: https://myvirtualcloud.net/how-to-implement-docker-swarm-with-postgresql-and-web-services-on-nutanix-acs-for-persistent-volumes/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

How to Implement Docker Swarm with PostgreSQL and Web-Services on Nutanix ACS Shared Volumes

  • 08/22/2016

In my previous article we deployed an open-source PACS solution on Nutanix using Acropolis Container Services (ACS) and created a persistent volume for the application and the database – a native MySQL.

While MySQL is the simplest solution as it is already backed into the application container, it has its limitations and is not scalable enough for enterprise deployments. This article focus on deploying the same application using a container with PostgreSQL database hosted with a persist volume for database files; while having Orthanc running on non-persistent containers in a Docker swarm cluster. Docker swarm enable the application to scale-out and also manages a built-in load balancer across container instances in the cluster.

The first step is to create a Host VM for PostgreSQL. That can also be the same VM where you host one of the Orthanc instances, but in my case I’m placing PostgreSQL in a dedicated Host VM. Since I’m using persistent volume with ACS for the database I can blow PostgreSQL off and easily recreate the service in a new Host VM.

Please refer to my previous article (here) for additional information on how to download and use the Nutanix Host Images and Image Management in Prism.

# docker-machine -D create -d nutanix –nutanix-username admin –nutanix-password ‘nutanix/4u’ –nutanix-endpoint ‘10.20.28.62:9440’ –nutanix-vm-image ContainerHost-20160818-Breeze –nutanix-vm-network ‘0’ nutanix-docker-vm-orthanc-postgres

# docker-machine ssh nutanix-docker-vm-orthanc-postgres

[root@nutanix-docker-vm-orthanc-postgres ~]# ./start-volume-plugin.sh

The command below will pull the PostgreSQL image from Docker hub and create and deploy a container names orthanc-postgres and map :/var/lib/postgresql as a persistent volume in ACS. This is where the PostgreSQL database files can be found.

[root@nutanix-docker-vm-orthanc-postgres ~] docker run -p 5432:5432 –volume-driver nutanix -v orthanc-postgres:/var/lib/postgresql –name orthanc-postgres -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=pgpassword postgres

Now let’s create the database in PostgreSQL. In order to create the database, you will need to open a new terminal windows and new ssh session.

# docker-machine ssh nutanix-docker-vm-orthanc-postgres

[root@nutanix-docker-vm-orthanc-postgres ~]# docker run -it –link orthanc-postgres:postgres –rm postgres sh -c ‘echo “CREATE DATABASE orthanc;” | exec psql -h “$POSTGRES_PORT_5432_TCP_ADDR” -p “$POSTGRES_PORT_5432_TCP_PORT” -U postgres’

Password for user postgres: pgpassword

CREATE DATABASE

Here is what you should see:

At this point you can delete and recreate PostgreSQL containers as you wish and you will always be able to reinstate the database using docker run command because the database files are hosted in a persistent volume in Nutanix ACS.

Next step is to create Orthanc application Host VMs. Let’s create 3 of them to be ‘workers’ in the swarm cluster.

# docker-machine -D create -d nutanix –nutanix-username admin –nutanix-password ‘nutanix/4u’ –nutanix-endpoint ‘10.20.28.62:9440’ –nutanix-vm-image ContainerHost-20160818-Breeze –nutanix-vm-network ‘0’ nutanix-docker-vm-orthanc-01

$ docker-machine ssh nutanix-docker-vm-orthanc-01

[root@nutanix-docker-vm-orthanc-01 ~]# docker run -p 4242:4242 -p 8042:8042 –name orthanc –rm jodogne/orthanc-plugins:latest

(repeat for nutanix-docker-vm-orthanc-02 and nutanix-docker-vm-orthanc-03)

Unfortunately, it’s only possible to configure Orthanc connection to PostgreSQL editing orthanc.json, and while you could create a docker image with the correct configuration I am opting for a difference solution that would enable me to very easily change the configuration for all containers at once. I’m creating a persistent volume that will hold the configuration file and every container will access this volume in read-only mode.

First create you must create a container with Orthanc and map the volume /etc/orthanc.

$ docker-machine ssh nutanix-docker-vm-orthanc-01

[root@nutanix-docker-vm-orthanc-01 ~]# docker run -p 4242:4242 -p 8042:8042 –volume-driver nutanix –name orthanc –rm -v orthanc-config:/etc/orthanc jodogne/orthanc-plugins

Now edit the /etc/orthanc/orthanc.json in the Orthanc container following the steps below.

Open a new terminal windows and type:

$ docker-machine ssh nutanix-docker-vm-orthanc-01

[root@nutanix-docker-vm-orthanc-01 ~]# docker exec -ti orthanc bash

root@1215d9f8365a:/# vi /etc/orthanc/orthanc.json

Add this snippet to the orthanc.json , save the file and exit the container.

“PostgreSQL” : {
“EnableIndex” : true,
“EnableStorage” : true,
“Lock” : false,
“Host” : “10.20.28.114”,
“Port” : 5432,
“Database” : “orthanc”,
“Username” : “postgres”,
“Password” : “pgpassword”
},

At this point you have finished the configuration for Orthanc and we are hosting orthanc.json in a persistent volume, however the volume is not shareable across container instances unless you specify within the volume group. Check ‘Share across multiple iSCSI initiators or multiple VMs”.

The final step is to ssh into each one of the orthanc host VMs and execute the command below. Please note the :ro specifying that the orthanc-config volume will be mounted as read-only. Optionally you may include –rm flag to delete the container after each run.

[root@nutanix-docker-vm-orthanc-01 ~]# docker run -p 4242:4242 -p 8042:8042 –volume-driver nutanix –name orthanc -v orthanc-config:/etc/orthanc:ro jodogne/orthanc-plugins

Docker Swarm

Whoa!!! That was long, but no configuration is required anymore to stand up 10 or 100 containers running Orthanc frontend – unless you want to automate it using Docker swarm. As I mentioned swarm enables the application to easily scale-out and also manages a built-in load balancer across container instances in the cluster. We will use orthanc-01 as the swam manager.

[root@nutanix-docker-vm-orthanc-01 ~]# docker swarm init

Now you should copy/paste the resulting command in each one of your Host VMs to tell them to join the Docker swarm cluster. Later this can be automated to enable Host VMs to automatically join swarm clusters.

The last step is to create the docker swarm service:

[root@nutanix-docker-vm-orthanc-01 ~]# docker service create –name orthanc -p 4242:4242 -p 8042:8042 andreleibovici/orthanc-nutanix:latest

[root@nutanix-docker-vm-orthanc-01 ~]# docker service create –mount type=volume,source=orthanc-config,target=/etc/orthanc,readonly=true,volume-driver=nutanix –name orthanc -p 4242:4242 -p 8042:8042 jodogne/orthanc-plugins:latest

Finally tell swarm to scale Orthanc container to 3 instances:

[root@nutanix-docker-vm-orthanc-01 ~]# docker service scale orthanc=3

You will be able to see your services running docker service ls or requesting a detailed inspection using docker service inspect orthanc

You can also list all tasks in the service just created using docker service ps orthanc

The much easier way would be to embed the changed configuration file into a docker image and upload to Docker Hub, but I feel that for this specific deployment the shared volumes with the configuration file achieves similar results.

In this post we created a service containing PostgreSQL database and a series of web-servers using Docker Swarm. The swarm service that is capable of scaling to hundreds of containers using Nutanix ACS for persistent volumes hosting database and configuration files. I’m working to automate this entire process and also adding something really cool as part of an upcoming Nutanix Hackathon project. I’ll soon discuss my implementation.

This article was first published by Andre Leibovici (@andreleibovici) at myvirtualcloud.net


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK