Skip to content

Latest commit

 

History

History
51 lines (36 loc) · 2.29 KB

File metadata and controls

51 lines (36 loc) · 2.29 KB

Envvar Configuration

This example assumes that you have a Kubernetes cluster to your avail. Please check INSTALL for various installation options.

First, lets create a ConfigMap and a Secert with one entry, respecively:

kubectl create configmap random-generator-config --from-literal=pattern=EnvVarConfiguration

kubectl create secret generic random-generator-secret --from-literal=seed=11232156346

We use both resource for defining environment variable in a simple Pod declaration for our sample random-generator REST service:

kubectl create -f https://k8spatterns.io/EnvVarConfiguration/pod.yml

If you look into this resource description, you see how our ConfigMap and Secret is used to set two environment variables PATTERN and SEED which are then also exposed via the random-generator rest service.

In order to access this rest service let’s expose the Pod via

kubectl create -f https://k8spatterns.io/EnvVarConfiguration/service.yml

For simplicity reasons, this service exposed the service port via a nodePort. Assuming, that your are using Minikube you can now access this service from your dekstop with:

port=$(kubectl get svc random-generator -o jsonpath={.spec.ports[0].nodePort})
curl -s http://$(minikube ip):$port/info | jq .

If you are not using Minikube, just insert the external facing IP address of one of your cluster’s node for the host address.

  • Do you se, how the environment variables are exposed ?

  • What happens when you change the data of the ConfigMap or Secret (e.g. with kubectl edit cm random-generator-config) ? Is this changed value reflected in the response of your curl request /

  • What would you have to do, to get this value returned in the HTTP response ?