Openshift

Infinispan Deployment.YAML on OpenShift Container Platform

Deploying Infinispan to OpenShift can be done easily by using either Operator or Helm chart. However, there is an even easier way to deploy it, and that is by using a single YAML file.

---
kind: Deployment
apiVersion: apps/v1
metadata:
  name: infinispan
  namespace: cache
  labels:
    app: infinispan
spec:
  replicas: 1
  selector:
    matchLabels:
      app: infinispan
  template:
    metadata:
      labels:
        app: infinispan
    spec:
      volumes:
        - name: data-volume
          persistentVolumeClaim:
            claimName: ispn-pv
      containers:
        - name: infinispan
          image: 'quay.io/infinispan/server:16.1'
          imagePullPolicy: IfNotPresent
          resources:
            limits:
              memory: 1Gi
            requests:
              memory: 1Gi
          env:
            - name: USER
              value: admin
            - name: PASS
              value: password
          ports:
            - name: infinispan
              containerPort: 11222
              protocol: TCP
          volumeMounts:
            - name: data-volume
              mountPath: /opt/infinispan/server/data
---
kind: Service
apiVersion: v1
metadata:
  name: infinispan
  namespace: cache
spec:
  ports:
    - protocol: TCP
      port: 11222
      targetPort: 11222
  selector:
    app: infinispan
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: ispn-pv
  namespace: cache
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi
  volumeMode: Filesystem

We can deploy this single file directly to OpenShift and have it up and running in a few minutes. However this approach is perfect for local development, testing, or a quick proof-of-concept. If you intend to scale Infinispan into a multi-node distributed cluster for production, you should migrate this configuration to a StatefulSet or leverage the official Infinispan Operator to handle cluster discovery and data replication.

Creating a Service Account to Access OpenShift Container Registry

Let’s say you want to create an OpenShift Container Registry account to be used by your CI/CD tooling. The recommended approach is to use a ServiceAccount instead of a regular user account. Here’s how you can do it.

First, create a ServiceAccount,

$ oc create serviceaccount david-susugigi-sa

Next, generate a token for this ServiceAccount. In this example, we create a long-lived token with a lifespan of two years

$ oc create token david-susugigi-sa --duration=16760h

eyJhbGciOiJ.....Gog8tY

Then, assign the appropriate role to the ServiceAccount

$ oc policy add-role-to-user system:image-builder -z david-susugigi-sa

Finally, use the ServiceAccount to log in to the registry, using the token as the password

$ podman login default-route-openshift-image-registry.apps-crc.testing \
      --tls-verify=false \ 
      -u david-susugigi-sa \ 
      -p eyJhbGciOiJ.....Gog8tY

Login Succeeded!

How to Solve “error, cannot create resource in API group” when Deploying Application with Jenkins and OpenShift

Had this error when im using Jenkins and integrate it to Openshift Container Platform

--> Creating resources with label build=hello-world-dot-net-core ...
    error: imagestreams.image.openshift.io is forbidden: User "system:serviceaccount:cicd:default" cannot create resource "imagestreams" in API group "image.openshift.io" in the namespace "cicd"
    error: buildconfigs.build.openshift.io is forbidden: User "system:serviceaccount:cicd:default" cannot create resource "buildconfigs" in API group "build.openshift.io" in the namespace "cicd"
--> Failed

How to solve this issue is actually quite simple, running this below command can solve it directly.

$ oc policy add-role-to-user admin system:serviceaccount:cicd:default -n cicd

Deploying a Binary WAR File to Openshift 4 Using s2i

We can leverage s2i to deploy an existing war file into Openshift 4. How to do it is pretty much simple and straight forward, basically just running some oc command and you can have your war file deployed on Openshift.

But before we go far, we need to have a sample application to be deployed and for this sample, i have a hello world apps which is created by using Java Servlet.

https://github.com/edwin/jboss-eap-hello-world

We can clone this application, and build it using a simple maven command.

$ mvn clean package

Next step is create an empty folder where we would run our oc command,

$ mkdir -p jboss-eap/deployments

and we can put our ROOT.war file inside deployment folder,

$ tree .
.
+---- deployments
    +---- ROOT.war

Next is creating a new BuildConfig,

$ oc new-build --name=custom-eap-application \
	--binary=true --image-stream=jboss-eap74-openjdk11-openshift:latest

and start building it by using a start-build command, we can also repeat this step again if there is a new changes to our war file

$ oc start-build custom-eap-application --from-dir . --follow

and finally we can deploy our application directly by using new-app command,

$ oc new-app --name=custom-eap-application \ 
	--image-stream=edwin-ns/custom-eap-application:latest

So deployment can be done easily by using just 3 simple steps.