How to create ConfigMap from directory using helm

7/13/2019

I have a folder having 3 json files in postman folder. How can I create ConfigMap using helm yaml template.

kubectl create configmap test-config --from- 
file=clusterfitusecaseapihelm/data/postman/

Above solution work, but I need this in yaml file as I am using Helm.

-- Vatan Soni
google-kubernetes-engine
kubectl
kubernetes
kubernetes-helm
kubernetes-ingress

1 Answer

7/14/2019

Inside a Helm template, you can use the Files.Glob and AsConfig helper functions to achieve this:

{{- (.Files.Glob "postman/**.json").AsConfig | nindent 2 }}

Or, to give a full example of a Helm template:

apiVersion: v1
kind: ConfigMap
metadata:
  name: test-config
data:
  {{- (.Files.Glob "postman/**.json").AsConfig | nindent 2 }}

See the documentation (especially the section on "ConfigMap and secrets utility functions") for more information.

-- helmbert
Source: StackOverflow