Skip to main content

Command Palette

Search for a command to run...

Run DB2 On OpenShift without the Operator

Published
2 min read

If you want to run DB2 on OpenShift you can use the DB2 Operator as described here Db2 12.1.2 for Red Hat OpenShift and Kubernetes;

As an alternative, you can do it without using the DB2 Operator;

Here is what you have to do if you don’t want to use the operator:

  1. Add the following permissions to your default OpenShift user:

     oc adm policy add-scc-to-user insights-runtime-extractor-scc -z default
    
  2. Create a PersistentVolumeClaim:

     apiVersion: v1
     kind: PersistentVolumeClaim
     metadata:
       name: db2-data-dir
     spec:
       accessModes:
         - ReadWriteMany
       resources:
         requests:
           storage: 100Mi
    
  3. Finally, deploy DB2:

     apiVersion: apps/v1
     kind: Deployment
     metadata:
       name: db2-deployment
       labels:
         app: db2
     spec:
       replicas: 1
       selector:
         matchLabels:
           app: db2
       template:
         metadata:
           labels:
             app: db2
         spec:
           containers:
             - name: db2
               image: icr.io/db2_community/db2:latest
               ports:
                 - containerPort: 50000
               env:
                 - name: LICENSE
                   value: "accept"
                 - name: DB2INSTANCE
                   value: "db2inst1"
                 - name: DB2INST1_PASSWORD
                   value: "password"
                 - name: DBNAME
                   value: "testdb"
                 - name: BLU
                   value: "false"
                 - name: ENABLE_ORACLE_COMPATIBILITY
                   value: "false"
                 - name: UPDATEAVAIL
                   value: "NO"
                 - name: TO_CREATE_SAMPLEDB
                   value: "true"
                 - name: REPODB
                   value: "false"
                 - name: PERSISTENT_HOME
                   value: "true"
                 - name: HADR_ENABLED
                   value: "false"
               volumeMounts:
                 - name: workdir1
                   mountPath: "/database"
               securityContext:
                 privileged: true
           volumes:
             - name: workdir1
               persistentVolumeClaim:
                 claimName: db2-data-dir
    
  4. Expose your DB2 Pod using a Service:

     kind: Service
     apiVersion: v1
     metadata:
       name: db2-service
     spec:
       ports:
         - protocol: TCP
           port: 50000
           targetPort: 50000
       selector:
         app: db2