Using your secrets
Once secrets have been created, they need to be linked to the application. This means that Kubernetes needs to pass the value of the secret to the running pods in some way. Kubernetes offers two ways to link your secrets to your application:
- Using secrets as environment variables
- Mounting secrets as files
Mounting secrets as files is the best way to consume secrets in your application. In this section, we will explain both methods, and also show why it's best to use the second method. Let's start by accessing secrets as environment variables.
Secrets as environment variables
You can use a secret in Kubernetes by referencing it as an environment variable. secrets can then be referenced in the pod definition under the containers
and env
sections. You will use the secrets that you previously created in a pod and learn how to use them in an application:
- You can configure a pod with environment variable secrets like the definition...