Openshift 3缺少OPENSHIFT_DATA_DIR环境变量(node.js) [英] Openshift 3 missing OPENSHIFT_DATA_DIR environment variable (node.js)

查看:118
本文介绍了Openshift 3缺少OPENSHIFT_DATA_DIR环境变量(node.js)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在openshift上运行一个node.js应用,我想添加一个存储卷.

I'm running a node.js app on openshift and I'd like to add a storage volume.

使用唯一的UI,我已经创建了一个永久卷声明,并使用添加存储"按钮在我的部署下添加了该卷.

Using the only UI I've already created a persistent volume claim, and added that volume under my deployment with the "Add Storage" button.

由于我的应用程序依赖对此存储的访问,因此我的node.js代码中包含以下内容:

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');
}

在部署时会抛出此错误,并且在查看console.log(process.env)的输出时似乎没有任何环境变量描述持久存储的路径.

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.

如何获取process.env.OPENSHIFT_DATA_DIR的值?

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.

还请记住,如果使用OpenShift Online,则当前存储类型只能与非扩展应用程序一起使用,并且不能使用滚动部署.因此,请确保将部署的部署策略从Rolling更改为Recreate,并且不要扩展应用程序.

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 to Recreate and don't scale your application.

这篇关于Openshift 3缺少OPENSHIFT_DATA_DIR环境变量(node.js)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆