I'm running a node.js app on openshift and I'd like to add a storage volume.
Using the only UI I've already created a persistent volume claim, and added that volume under my deployment with the "Add Storage" button.
Because my application relies on access to this storage, I have the following in my node.js code:
if (!('OPENSHIFT_DATA_DIR' in process.env)) {
console.log(process.env);
throw new Error('Can\'t access data directory');
}
This error is thrown upon deployment, and upon reviewing the output of console.log(process.env)
there doesn't seem to be any environment variable describing a path for persistent storage.
How can I get a value for process.env.OPENSHIFT_DATA_DIR
?
You can set yourself on the deployment config the environment variable, giving it the path that you mounted the persistent volume into your container. That or just code the path into your application code.
This presumes you did actually mount the persistent volume into your container. It is not enough just to make a claim, it does need to then be associated with the application.
Also keep in mind that the current storage type, if using OpenShift Online, can only be used with non scaled applications and you cannot use rolling deployments. So make sure you change the deployment strategy of the deployment from
Rolling
toRecreate
and don't scale your application.