The steps below assume that you are using minishift (https://github.com/minishift/minishift) to run an Openshift cluster locally.
Prefereably, these steps need to be carried out before initiating an application with the template above. If not, the PostgreSQL database pod will not start up and you will have to re-deploy the PostgreSQL pod after carrying out the steps below. It's not a major problem. But why panick unnecessarily? :)
The Django persistent template can be found at https://github.com/openshift/django-ex
`wget https://raw.githubusercontent.com/openshift/django-ex/master/openshift/templates/django-postgresql-persistent.json`
`oc create -f django-postgresql-persistent.json`
`oc login -u system:admin`
The example configuration file below creates a persisted volume named 'pv-postgres'.
The PostgreSQL instance from the template will create a storage claim named 'postgresql' in my openshift environment.
When the application is instantiated, I am planning to nominate 1GB of storage for PostgreSQL. Since I have given the same capacity of 1GB to my persistent volume, openshift will automatically bind the 'postgresql' claim to my 'pv-postgres' volume.
Save the below persistent volume configuration to a file named persistent-config.json.
This configuration creates a persistent volume using the host path /var/lib/minishift/pv-postgres. In a production like environment, this will be an NFS mount.
NOTE: Indentation is important when you save the content below into your file.
apiVersion: "v1"
kind: "PersistentVolume"
metadata:
name: "pv-postgres"
spec:
accessModes:
- "ReadWriteOnce"
capacity:
storage: "1Gi"
hostPath:
path: "/var/lib/minishift/pv-postgres"
Now, from the same directory as the file above, run the following oc command.
'oc create -f persistent-config.json`
This creates the directory /var/lib/minishift/pv-postgres inside the minishift Docker host.
`oc get pv` (Lists persistent volumes)
`oc get pvc` (Lists persistent volume claims)
`minishift ssh`
`cd /var/lib/minishift/`
`sudo chmod 777 pv-postgres` (Caution: Do 777 only in your local setup. This makes the directory world writeable)
Finally - Create your application using the django postgresql template via “Add to Project” wizard.
The screenshot below (openshift-persistent-volume.png) shows how your openshift console's "Storage" view will look like, if all went well.
Copyright (c) 2017 Tyrell Perera [email protected] Licensed under the MIT license.