Friday, 13 March 2015

Infinispan on Openshift v3


Openshift v3 is the open source next generation of Paas, where applications run on Docker containers and are orchestrated/controlled/scheduled by Kubernetes.

In this post I'll show how to create an Infinispan cluster on Openshift v3 and resize it with a snap of a finger.

Installing Openshift v3

 

Openshift v3 has not been released yet, so I'm going to use the code from origin.
There are many ways to install Openshift v3, but for simplicity, I'll run a full multinode cluster locally on top of VirtualBoxes using the provided Vagrant scripts.

Let's start by checking out and building the sources:


To boot Openshift, it's a simple matter of starting up the desired number of nodes:

Grab a beer while the cluster is being provisioned, after a while you should be able to see 3 instances running:


 

Creating the Infinispan template


The following template defines a 2 node Infinispan cluster communicating via TCP, and discovery done using the JGroups gossip router:


There are few different components declared in this template:

  • A service with id jgroups-gossip-service that will expose a JGroups gossip router service on port 11000, around the JGroups Gossip container
  • A ReplicationController with id jgroups-gossip-controller. Replication Controllers are used to ensure that, at any moment, there will be a certain number of replicas of a pod (a group of related docker containers) running. If for some reason a node crashes, the ReplicationController will instantiate a new pod elsewhere, keeping the service endpoint address unchanged.
  • Another ReplicationController with id infinispan-controller. This controller will start 2 replicas of the infinispan-pod. As it happens with the jgroups-pod, the infinispan-pod has only one container defined: the infinispan-server container (based on jboss/infinispan-server) , that is started with the 'clustered.xml' profile and configured with the 'jgroups-gossip-service' address. By defining the gossip router as a service, Openshift guarantees that environment variables such as JGROUPS_GOSSIP_SERVICE_SERVICE_HOST are available to other pods (consumers).


Applying the template



To apply the template via cmd line:

Grab another beer, it can take a while since in this case the docker images need to be fetched on each of the minions from the public registry. In the meantime, to inspect the pods, along with their containers and statuses:


Resizing the cluster


Changing the number of pods (and thus the number of nodes in the Infinispan cluster) is a simple matter of manipulating the number of replicas in the Replication Controller. To increase the number of nodes to 4:


This should take only a few seconds, since the docker images are already present in all the minions.



And this concludes the post, be sure to check other cool features of Openshift in the project documentation and try out other samples.

5 comments:

  1. Hey Gustavo, all the console commands got lost in the process!

    ReplyDelete
    Replies
    1. I can see them Ugo, maybe the gists were temporary offline?

      Delete
  2. Good stuff Gustavo !
    Q: why didn't you use the discovery protocol for OpenShift/Swift [1] that you wrote ?
    [1] https://github.com/belaban/JGroups/blob/master/src/org/jgroups/protocols/SWIFT_PING.java

    ReplyDelete
    Replies
    1. Hi, looks like SWIFT_PING is for Openstack storage

      Delete
  3. This comment has been removed by the author.

    ReplyDelete