Create Data Grid clusters running on OpenShift with the Infinispan
CR or with the native Data Grid CLI plugin for oc
clients.
Infinispan custom resource (CR)
Data Grid Operator adds a new Custom Resource (CR) of type Infinispan
that lets you handle Data Grid clusters as complex units on OpenShift.
Data Grid Operator listens for Infinispan
Custom Resources (CR) that you use to instantiate and configure Data Grid clusters and manage OpenShift resources, such as StatefulSets and Services.
Infinispan
CR
apiVersion: infinispan.org/v1
kind: Infinispan
metadata:
name: infinispan
spec:
replicas: 2
service:
type: DataGrid
Field | Description |
---|---|
|
Declares the version of the |
|
Declares the |
|
Specifies a name for your Data Grid cluster. |
|
Specifies the number of pods in your Data Grid cluster. |
|
Specifies the type of Data Grid service to create. |
Creating Data Grid clusters
Create Data Grid clusters with the native CLI plugin, kubectl-infinispan
.
-
Install Data Grid Operator.
-
Have
kubectl-infinispan
on yourPATH
.
-
Run the
infinispan create cluster
command.For example, create a Data Grid cluster with two pods as follows:
$ oc infinispan create cluster --replicas=3 -Pservice.type=DataGrid infinispan
-
Watch Data Grid Operator create the Data Grid pods.
$ oc get pods -w NAME READY STATUS RESTARTS AGE infinispan-0 0/1 ContainerCreating 0 4s infinispan-0 1/1 Running 0 17s infinispan-1 0/1 Pending 0 0s infinispan-1 0/1 ContainerCreating 0 4s infinispan-1 1/1 Running 0 20s infinispan-2 0/1 Pending 0 0s infinispan-2 0/1 ContainerCreating 0 4s infinispan-2 1/1 Running 0 32s
After you create a Data Grid cluster, use the oc
to apply changes to Infinispan
CR and configure your Data Grid service.
You can also delete Data Grid clusters with kubectl-infinispan
and re-create them as required.
$ oc infinispan delete cluster infinispan
Verifying Data Grid cluster views
Confirm that Data Grid pods have successfully formed clusters.
-
Create at least one Data Grid cluster.
-
Retrieve the
Infinispan
CR for Data Grid Operator.$ oc get infinispan -o yaml
The response indicates that Data Grid pods have received clustered views, as in the following example:
conditions: - message: 'View: [infinispan-0, infinispan-1]' status: "True" type: wellFormed
Do the following for automated scripts:
$ oc wait --for condition=wellFormed --timeout=240s infinispan/infinispan
Alternatively, you can retrieve cluster view from logs as follows:
$ oc logs infinispan-0 | grep ISPN000094
INFO [org.infinispan.CLUSTER] (MSC service thread 1-2) \
ISPN000094: Received new cluster view for channel infinispan: \
[infinispan-0|0] (1) [infinispan-0]
INFO [org.infinispan.CLUSTER] (jgroups-3,infinispan-0) \
ISPN000094: Received new cluster view for channel infinispan: \
[infinispan-0|1] (2) [infinispan-0, infinispan-1]
Modifying Data Grid clusters
Configure Data Grid clusters by providing Data Grid Operator with a custom Infinispan
CR.
-
Install Data Grid Operator.
-
Create at least one Data Grid cluster.
-
Have an
oc
client.
-
Create a YAML file that defines your
Infinispan
CR.For example, create a
my_infinispan.yaml
file that changes the number of Data Grid pods to two:$ cat > cr_minimal.yaml<<EOF apiVersion: infinispan.org/v1 kind: Infinispan metadata: name: infinispan spec: replicas: 2 service: type: DataGrid EOF
-
Apply your
Infinispan
CR.$ oc apply -f my_infinispan.yaml
-
Watch Data Grid Operator scale the Data Grid pods.
$ oc get pods -w
Stopping and starting Data Grid clusters
Stop and start Data Grid pods in a graceful, ordered fashion to correctly preserve cluster state.
Clusters of Data Grid service pods must restart with the same number of pods that existed before shutdown. This allows Data Grid to restore the distribution of data across the cluster. After Data Grid Operator fully restarts the cluster you can safely add and remove pods.
-
Change the
spec.replicas
field to0
to stop the Data Grid cluster.spec: replicas: 0
-
Ensure you have the correct number of pods before you restart the cluster.
$ oc get infinispan infinispan -o=jsonpath='{.status.replicasWantedAtRestart}'
-
Change the
spec.replicas
field to the same number of pods to restart the Data Grid cluster.spec: replicas: 6