With Container orchestration tools like Kubernetes and Docker Swarm, you can add instances quite easily. Depending on the type of clustering you need or use for your application, some scenarios are easier to implement than others.
In this blog, I give you an overview of the clustering possibilities when using the Payara Platform in combination with container orchestration tools so you can choose the optimal solution for your case.
Payara Server Deployment Group
The Deployment Group, introduced in Payara Server 5, allows you to create a set of instances that can be targeted for deploying your application. It is a very flexible form of clustering and with the Domain Data Grid, information can easily be shared by the different instances. For a basic overview of the feature, you can have a look at this blog, Deployment Groups in Payara Server 5, and this documentation page: Deployment Groups.
However, using this deployment feature in combination with container Orchestration tools is a challenge. After you have started another container, for example, there are additional steps required before that Payara Server instance is fully operational within the Deployment Group. Some asadmin commands need to to be executed to join the Deployment Group.
To use the dynamic features of the cloud infrastructures, like quickly adding and removing instances for your application, we have started to create a deeply integrated Node Type with the Docker Platform.
With the release of Payara Server 5.192, the concept of a Docker Node was introduced. You can read more about this feature in the blog, What's New in Payara Platform 5.192 . With this Docker Node, using the Deployment Group feature in combination with tools like Kubernetes and Docker Swarm becomes easier as The Payara Server is aware that this node is running within a Docker container and is aware of the life-cycle of it.
Within future versions of the platform, the integration will be improved and support for scaling will be added.
Data Grid Option
Another option is to cluster just your application data through the Data Grid feature of Payara Platform. The instances are now more or less isolated, but your application data, like a read-only cache, is shared between the different instances.
This setup can be created using Payara Server or Payara Micro instances (or even a combination of both if you like).
When you like to use Payara Server, you can indicate that the Data Grid feature needs to use the multicast protocol to discover other instances on the same network segment. When you add the following asadmin command to a file which is used during the start of the server, the Post Boot Command File, the instances will discover each other:
set-hazelcast-configuration --clusterMode=multicast --multicastGroup=184.108.40.206 --multicastPort=54327 --dynamic=true
This also means that data, like the read-only data cache I mentioned previously, can be shared between all the instances.
Another advantage of using the Domain Server directly, and not Payara Instances which are grouped within a Deployment Group, is that you can start from your base Docker image with Payara, and through a volume share, add the previously mentioned Post Boot Command file. This can contain additional configuration aspects of your application like a database connection, for example.
Of course, you can create a specific Docker Image for your application, with the asadmin commands within the Image so that the image is used in an unchanged way.
The same setup can also be made with the Payara Micro runtime. The set-hazelcast-configuration command is not required in this case as it is the default discovery mechanism for Payara Micro.
The choice, using Payara Server or Payara Micro, then just depends on what kind of API you want to use in your application. The Payara Micro runtime is mainly built around the Web API of Java EE whereas the Payara Server can run a Java EE full API application. The latter also come with an OSGI runtime, so when you do not need this, or the Java EE Full API, the Payara Micro solution is the preferred one.
You can read more about this clustering option in our "Clustering Payara Server in Docker Guide".
Payara Server 5.192 Improves the Use of a Deployment Group in a Container Environment
When you like to use the Payara Platform with the container orchestration tools, like Kubernetes and Docker Swarm, it is probably easier to not use the Deployment Group feature. This feature requires some additional commands to add an individual Payara instance to the Deployment Group.
However, with the release of Payara Server 5.192, we have started to improve the usage of the Deployment Group in a container environment by implementing the Docker Node. So it will be possible in a future version to also use the Deployment Group fairly easily in combination with the container orchestration tools.