Search code examples
node.jskubernetesdeploymentenvironment-variablesdotenv

Access secrets as environment variables in Kubernetes


I'm using Secrets as an environmental variable and I was wondering how you would call the secret in the client side of my application? I'm running a Node.js application and want to use the Secrets environmental variable. I would normally call my environment variables by doing process.env.VARIABLE_NAME locally since I have an env file, but I know that it's not the same for a secret as environmental variable when deployed onto Kubernetes.

Could anybody help me with this? Thanks!


Solution

  • After days of figuring out how to use Secrets as an environmental variable, I figured out how to reference it in my nodejs application!

    Before I was doing the normal way of calling environmental variables, process.env.VARIABLE_NAME, but that did not work for me when I had Secrets as an environment variable. In order to get the value of the variable, I had to do process.env.ENVIRONMENTAL_VARIABLES_USERNAME in my Javascript file and that worked for me! Where ENVIRONMENTAL_VARIABLES is the name and USERNAME is the key! Refer to my other question for clarification: Environmental variables returning undefined for Kubernetes deployment

    Not sure if this will help anyone else but this is how I managed to access my Secrets in my nodejs application!