0

We use Pivotal Cloud Foundry's YML file to set up the environment. Everything is fine. According to DEVOPS if we have to modify/create an environment variable, we have to modify YML and push the app again. I am wondering if it is possible to modify/create an environment variable while the PCF app is running. It will be really cool if it can be done without having to redeploy the app. If it can't be done, is it because of Java's way of handling the environment?

Thanks

1 Answers1

2

Can we change/modify the environment in PCF (Pivotal Cloud Foundy) at Runtime?

Yes and no.

You can modify environment variables associated with an application while the application is running using the cf set-env (to set or update) and cf unset-env (to delete).

This will update the environment variable in Cloud Controller at the time you run the command. However, this will not update the environment variable inside of a running application container. In order for your application to see the change that you made, you must cf restart, cf restage or cf push.

This has nothing to do with language specifics (i.e. it doesn't matter what language you're using). It is a requirement because the container where your application is running gets created with a fixed set of environment variables. When those change, the container must be recreated. That said, even if the container could be changed at runtime, in Linux a process' environment variables cannot be updated externally at runtime either (there are technically some ways to do this, but it's really unlikely you'd do this in practice). The process itself should be restarted for environment variables to change.

If you want to have your configuration update at runtime, you can look at something like Spring Cloud Config server & its refresh capabilities. That said, it turns out that most applications and frameworks assume configuration is read once while the app is starting up, so your application would need to support changing the configuration you want to change at runtime as well.

Daniel Mikusa
  • 13,716
  • 1
  • 22
  • 28
  • Thank you for your thoughtful response. I think for computers to be really useful, they should dynamically adapt to changing environment and needs. That is AI and a wishful thinking. Regards – user2649568 Aug 08 '20 at 21:34