1

This example shows how to use ConfigMaps with openliberty.

The problem to me is that you have to create a section for the env variable in each of kubernetes deployment.

containers:
      - name: system-container
        image: system:1.0-SNAPSHOT
        ports:
        - containerPort: 9080
        # Set the environment variables
        env:
        - name: CONTEXT_ROOT
          valueFrom:
            configMapKeyRef:
              name: sys-app-root
              key: contextRoot
        - name: SYSTEM_APP_USERNAME
          valueFrom:
            secretKeyRef:
              name: sys-app-credentials
              key: username
        - name: SYSTEM_APP_PASSWORD
          valueFrom:
            secretKeyRef:
              name: sys-app-credentials
              key: password

Wouldn't it be just easier to upload microprofile-config.properties as
a ConfigMap and mount it as volume to the right location?

Wytrzymały Wiktor
  • 11,492
  • 5
  • 29
  • 37
FreshMike
  • 481
  • 1
  • 6
  • 26

2 Answers2

0

You dont have to create env part for each value. You can create your config map from microprofile-config.properties file and then just use envFrom to load all the key pairs like this:

      envFrom:
      - configMapRef:
          name: my-microprofile-config

But maybe I missed your real problem...

Gas
  • 17,601
  • 4
  • 46
  • 93
0

Since you're using open-liberty I also think that creating your own config-map using microprofile-config.properties file will be good idea.


According to this documentation:

MicroProfile Config allows you to define configuration values, which are referred to as "config property" values, in a huge range of locations that are known as ConfigSources.

To load all the key pairs one can use envForm (just like @Gus suggested).

According to this documentation: One can use envForm to define all of the ConfigMap's data as container environment variables.

The key from the ConfigMap becomes the environment variable name in the Pod.

Here is the example of use envForm:

apiVersion: v1
kind: Pod
metadata:
  name: dapi-test-pod
spec:
  containers:
    - name: test-container
      image: k8s.gcr.io/busybox
      command: [ "/bin/sh", "-c", "env" ]
      envFrom:
      - configMapRef:
          name: special-config
  restartPolicy: Never

To load all the key pairs you need this scrap:

      envFrom:
      - configMapRef:
          name: special-config

See also this and this documentations.

kkopczak
  • 742
  • 2
  • 8