- Use the official Kubernetes documentation for this exercise. https://kubernetes.io/docs/concepts/configuration/configmap/ and https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/ should contain everything you need.
- Create a ConfigMap for a "dotenv file". A file where you define environment variables that are loaded by the application. For this use an environment variable "MESSAGE" with value "Hello" to test and print the value. The values from ConfigMap can be either saved to a file and read by the application, or set as environment variables and used by the application through that.
- Update app to retrieve
MESSAGE
variable from environment. - Add
envFrom
in spec of a container in your deployment. - (This is the way I did it): Create a
.env
file. - Add
kubectl
command to create a configmap after creating a cluster:kubectl create configmap newconfig --from-env-file=.env --namespace=logtest
- This http://localhost:8081/pingpong should show your `MESSAGE` environment variable.
- cd to this directory, run `make relaunch-cluster`. It should show your `MESSAGE` environment variable as configured in the app.
Source: DevOps with Kubernetes