ConfigMaps, Secrets, Env Var
ConfigMaps, Secrets and Environment Variables#
In this section we'll take a look at how OSToy can be configured using ConfigMaps, Secrets, and Environment Variables. This section won't go into details explaining each (the links above are for that), but will show you how they are exposed to the application.
1. Configuration using ConfigMaps#
ConfigMaps allow you to decouple configuration artifacts from container image content to keep containerized applications portable.
Click on Config Maps in the left menu.
This will display the contents of the configmap available to the OSToy application. We defined this in the
2. Configuration using Secrets#
Kubernetes Secret objects allow you to store and manage sensitive information, such as passwords, OAuth tokens, and SSH keys. Putting this information in a secret is safer and more flexible than putting it, verbatim, into a Pod definition or a container image.
Click on Secrets in the left menu.
This will display the contents of the secrets available to the OSToy application. We defined this in the
3. Configuration using Environment Variables#
Using environment variables is an easy way to change application behavior without requiring code changes. It allows different deployments of the same application to potentially behave differently based on the environment variables, and OpenShift makes it simple to set, view, and update environment variables for Pods/Deployments.
Click on ENV Variables in the left menu.
This will display the environment variables available to the OSToy application. We added four as defined in the deployment spec of
env: - name: ENV_TOY_CONFIGMAP valueFrom: configMapKeyRef: name: ostoy-configmap-env key: ENV_TOY_CONFIGMAP - name: ENV_TOY_SECRET valueFrom: secretKeyRef: name: ostoy-secret-env key: ENV_TOY_SECRET - name: MICROSERVICE_NAME value: OSTOY_MICROSERVICE_SVC - name: NAMESPACE valueFrom: fieldRef: fieldPath: metadata.namespace
You may have to do a
ctrl+f to find them. Search for the three names above.
The one called,
MICROSERVICE_NAME is used for the intra-cluster communications between pods for this application. The application looks for this environment variable to know how to access the microservice in order to get the colors.