<p>There are two ways you can manage this :</p>
<ul>
<li>Like you said, make the secret data available trough environnement variables and run <code>sed</code> or <code>envsubst</code> on the file before startup.</li>
<li>Or, you could create a secret that would hold your whole PropertyFile content, and then use that secret trough a <code>volume</code> to mount its content as a file in your Pod (see <a href="https://kubernetes.io/docs/tasks/inject-data-application/distribute-credentials-secure/#create-a-pod-that-has-access-to-the-secret-data-through-a-volume" rel="nofollow noreferrer">this example</a> in the documentation for more informations). But since you only have one secret data in your PropertyFile, this might be overkill, depending on your setup.</li>
</ul>
<p>I wouldn't know what option is the best in your situation, but these the one I would suggest.</p>

CC BY-SA 4.0
2023-12-27T15:04:51.557Z
I have worked with linux for 20 years, how have I never heard of envsubst before.
Nifle
CC BY-SA 4.0
2023-12-19T13:53:51.463Z
2023-12-19T13:53:51.463Z
ABWassim
<p>I am new to openshift and kubernetes.</p>
<p>I have a secret in openshift and made it avaliable to the pod as an environment variable.</p>
<p>What is the <em>best practice</em> to get that value into a properies file (java) before the containers service starts?</p>
<p>Is there a better way than using <code>sed</code> on the propertyfile before startup?</p>

<kubernetes><openshift><secret-management>
How do I get a secret into a property file with openshift and kubernetes?
Nifle
# How do I get a secret into a property file with openshift and kubernetes?

(Asked by: username_0 on 2023-12-15)

I am new to openshift and kubernetes.

I have a secret in openshift and made it avaliable to the pod as an environment variable.

What is the *best practice* to get that value into a properies file (java) before the containers service starts?

Is there a better way than using `sed` on the propertyfile before startup?

**Tags:** kubernetes, openshift, secret-management


---

## 1 answers

### Answer by username_1 on 2023-12-19. Score: 1 | Accepted answer

There are two ways you can manage this :

* Like you said, make the secret data available trough environnement variables and run `sed` or `envsubst` on the file before startup.
* Or, you could create a secret that would hold your whole PropertyFile content, and then use that secret trough a `volume` to mount its content as a file in your Pod (see [this example](https://kubernetes.io/docs/tasks/inject-data-application/distribute-credentials-secure/#create-a-pod-that-has-access-to-the-secret-data-through-a-volume) in the documentation for more informations). But since you only have one secret data in your PropertyFile, this might be overkill, depending on your setup.

I wouldn't know what option is the best in your situation, but these the one I would suggest.

> **Comments:**
> **username_0**: I have worked with linux for 20 years, how have I never heard of envsubst before.  

---

