Over a million developers have joined DZone.

Infinispan Configuration Management on OpenShift, Kubernetes, and Docker

When deploying Infinispan on Docker-based cloud environments, the most critical thing is how to manage configuration. In this blog post we'll explore some of the options.

· Database Zone

Sign up for the Couchbase Community Newsletter to stay ahead of the curve on the latest NoSQL news, events, and webinars. Brought to you in partnership with Coucbase.

If you're trying to get Infinispan up and running on the cloud, you'll have to get it configured. That's where it gets tricky. Fortunately, if you're using a Docker-based environment, you can follow along while we show you the way.

Extending Our Docker Image

Creating your own Docker image based on jboss/infinispan-server is quite simple. First, you need to prepare a configuration XML file, which is shipped with Infinispan release. Go to the Infinispan download section and grab a server release corresponding to a chosen Docker image tag. After unpacking it, grab the configuration (I use cloud.xml as a template) and introduce all necessary changes. 

Finally, build your image:

FROM jboss/infinispan-server

COPY custom-cloud.xml /opt/jboss/infinispan-server/standalone/configuration/cloud.xml


Now, that was quick, wasn't it?

Using ConfigMaps With OpenShift

If you're using OpenShift, there's a sophisticated tool called ConfigMap. A ConfigMap can store a configuration file (or a configuration directory) and mount it somewhere in the Pod.

Use the command below to create a ConfigMap based on a configuration file:

$ oc create configmap cloud-xml --from-file=custom-cloud.xml                                                 
configmap "cloud-xml" created


Now create Infinispan application based on the configuration below (you can use 'oc create -f <file.yaml>' for this):

apiVersion: v1
items:
- apiVersion: v1
  kind: DeploymentConfig
  metadata:
    labels:
      app: infinispan-server
    name: infinispan-server
  spec:
    replicas: 1
    selector:
      app: infinispan-server
      deploymentconfig: infinispan-server
    template:
      metadata:
        labels:
          app: infinispan-server
          deploymentconfig: infinispan-server
      spec:
        containers:
        - args:
          - custom/custom-cloud
          - -Djboss.default.jgroups.stack=kubernetes
          image: jboss/infinispan-server
          imagePullPolicy: Always
          name: infinispan-server
          ports:
          - containerPort: 8181
            protocol: TCP
          - containerPort: 8888
            protocol: TCP
          - containerPort: 9990
            protocol: TCP
          - containerPort: 11211
            protocol: TCP
          - containerPort: 11222
            protocol: TCP
          - containerPort: 57600
            protocol: TCP
          - containerPort: 7600
            protocol: TCP
          - containerPort: 8080
            protocol: TCP
          terminationMessagePath: /dev/termination-log
          volumeMounts:
          - mountPath: /opt/jboss/infinispan-server/standalone/configuration/custom
            name: config-volume
        restartPolicy: Always
        volumes:
        - configMap:
            name: cloud-xml
          name: config-volume
    triggers:
    - type: ConfigChange
kind: List
metadata: {}


  • (lines 50 - 52) - ConfigMap volume declaration
  • (lines 45 - 47) - Mounting configuration into /opt/jboss/infinispan-server/standalone/configuration/custom
  • (line 22) - bootstrapping the Infinispan with custom configuration (note there is no xml extension there)

Using ConfigMaps With Kubernetes

Kubernetes ConfigMaps work exactly the same way as in OpenShift.

The command below creates a ConfigMap:

$ kubectl create configmap cloud-xml --from-file=cloud.xml
configmap "cloud-xml" created


The second step is to create a Deployment with ConfigMap:

apiVersion: v1
items:
- apiVersion: extensions/v1beta1
  kind: Deployment
  metadata:
    annotations:
    labels:
      run: infinispan-server
    name: infinispan-server
    namespace: default
  spec:
    replicas: 3
    selector:
      matchLabels:
        run: infinispan-server
    strategy:
      rollingUpdate:
        maxSurge: 1
        maxUnavailable: 1
      type: RollingUpdate
    template:
      metadata:
        creationTimestamp: null
        labels:
          run: infinispan-server
      spec:
        containers:
        - args:
          - custom/cloud
          - -Djboss.default.jgroups.stack=kubernetes
          env:
          - name: OPENSHIFT_KUBE_PING_NAMESPACE
            valueFrom:
              fieldRef:
                apiVersion: v1
                fieldPath: metadata.namespace
          image: jboss/infinispan-server
          imagePullPolicy: Always
          name: infinispan-server
          ports:
          - containerPort: 8080
            protocol: TCP
          - containerPort: 8181
            protocol: TCP
          - containerPort: 8888
            protocol: TCP
          - containerPort: 9990
            protocol: TCP
          - containerPort: 11211
            protocol: TCP
          - containerPort: 11222
            protocol: TCP
          resources: {}
          terminationMessagePath: /dev/termination-log
          volumeMounts:
          - mountPath: /opt/jboss/infinispan-server/standalone/configuration/custom
            name: config-volume
        dnsPolicy: ClusterFirst
        restartPolicy: Always
        securityContext: {}
        volumes:
        - configMap:
            name: cloud-xml
          name: config-volume
        terminationGracePeriodSeconds: 30
kind: List
metadata: {}


Conclusion

If you're using any Docker orchestration tool — have a look at the provided tools. OpenShift and Kubernetes ConfigMaps are really great for this.

However if you need a fine-grained control — either extend our Docker image (this is the preferred way) or simply fork and modify it.

Happy configuring and scaling!

The Getting Started with NoSQL Guide will get you hands-on with NoSQL in minutes with no coding needed. Brought to you in partnership with Couchbase.

Topics:
infinispan ,configuration management ,openshift ,kubernetes ,docker ,database

Published at DZone with permission of Manik Surtani, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}