manu muraleedharan
manu muraleedharan

Reputation: 435

Is there any way to load a JSON file directly into kubernetes environment variables or configmap?

I have a set of key value pairs in a JSON file that would be mounted in the container. Is there any way to load them directly as environment variables or configmap in Kubernetes directly? I have currently a fallback script to read the file and parse using linux commands, but I am looking for an elegant and/or standard way in Kube to do this. This kube is inside EKS if that is a consideration.

For eg, file; {key1:value1,key2:value2}

Once done, it should create environment variables like; echo $key2 value2

Upvotes: 0

Views: 2444

Answers (1)

CaioT
CaioT

Reputation: 2211

You can load the json file into a configMap and then map it to environment variables in your definition file.

kubectl create configmap name-of-your-configmap --from-file=your-file.json

Then in your yaml definition file:

spec:
  containers:
      ...
      envFrom:
      - configMapRef:
          name: name-of-your-configmap

Upvotes: 1

Related Questions