Kubernetes ConfigMap JSON list to .NET Core config

11/22/2019

I'm having troubles writing configuration down for a list in configmap.

My deployment file has this value

- name: CORS__EnabledOrigins
          valueFrom:
            configMapKeyRef:
              name: cors
              key: EnabledOrigins

And the ConfigMap looks like this

apiVersion: v1
kind: ConfigMap
metadata:
  namespace: dev
  name: cors
data:
  EnabledOrigins: | 
    [ "https://url1.net", "https://url2.com" ]

When my .NET Core pod tries to start it cannot read the configuration as a proper list unless I define a bunch of value with indexes such as EnabledOrigins__0 both in deployment and config files. But obviously that is a bad solution since you have to predefine how many values you will have or change both the ConfigMap and deployment template to apply new changes. Is there any other way to define a ConfigMap so that it can be passed to deployment template by just one key but is then expanded to multiple keys with indexes so that the application doesn't just see it as one string?

-- Homulvas
asp.net-core
kubernetes

0 Answers