|
1 | 1 | == Envvar Configuration |
2 | 2 |
|
3 | | -IMPORTANT: The instructions have not been written/finished, but the resource file has been verified. Instructions will be added soon. |
| 3 | +This example assumes that you have a Kubernetes cluster to your avail. |
| 4 | +Please check link:../../INSTALL.adoc#minikube[INSTALL] for various installation options. |
| 5 | + |
| 6 | +First, lets create a ConfigMap and a Secert with one entry, respecively: |
4 | 7 |
|
5 | 8 | [source, bash] |
6 | 9 | ---- |
7 | 10 | kubectl create configmap random-generator-config --from-literal=pattern=EnvVarConfiguration |
8 | 11 |
|
9 | 12 | kubectl create secret generic random-generator-secret --from-literal=seed=11232156346 |
| 13 | +---- |
10 | 14 |
|
| 15 | +We use both resource for defining environment variable in a simple Pod declaration for our sample https://github.com/k8spatterns/random-generator[random-generator REST service]: |
11 | 16 |
|
12 | | -kubectl create -f pod.yml |
| 17 | +[source, bash] |
| 18 | +---- |
| 19 | +kubectl create -f https://k8spatterns.io/EnvVarConfiguration/pod.yml |
| 20 | +---- |
13 | 21 |
|
14 | | -kubectl create -f service.yml |
| 22 | +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. |
15 | 23 |
|
| 24 | +In order to access this rest service let's expose the Pod via |
16 | 25 |
|
| 26 | +[source, bash] |
| 27 | +---- |
| 28 | +kubectl create -f https://k8spatterns.io/EnvVarConfiguration/service.yml |
| 29 | +---- |
| 30 | + |
| 31 | +For simplicity reasons, this service exposed the service port via a `nodePort`. |
| 32 | +Assuming, that your are using Minikube you can now access this service from your dekstop with: |
| 33 | + |
| 34 | +[source, bash] |
| 35 | +---- |
17 | 36 | port=$(kubectl get svc random-generator -o jsonpath={.spec.ports[0].nodePort}) |
18 | 37 | curl -s http://$(minikube ip):$port/info | jq . |
19 | | -
|
20 | | -{ |
21 | | - "memory.free": 24, |
22 | | - "seed": 11232156346, |
23 | | - "memory.used": 46, |
24 | | - "cpu.procs": 1, |
25 | | - "memory.max": 481, |
26 | | - "logFile": "/tmp/random.log", |
27 | | - "pattern": "EnvVarConfiguration", |
28 | | - "id": "b5942022-5925-4672-9c26-8cf255b5ccf0", |
29 | | - "version": "1.0" |
30 | | -} |
31 | 38 | ---- |
32 | 39 |
|
| 40 | +If you are not using Minikube, just insert the external facing IP address of one of your cluster's node for the host address. |
33 | 41 |
|
| 42 | +* Do you se, how the environment variables are exposed ? |
| 43 | +* 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 / |
| 44 | +* What would you have to do, to get this value returned in the HTTP response ? |
34 | 45 |
|
35 | 46 | === More Information |
36 | 47 |
|
|
0 commit comments