<p>I have a container running in a pod which requires a single config file.  The deployment/service etc are deployed using helm, and ideally I'd like to use the same method to setup the config, and if possible, I'd like to use helm's templating engine to template the config file.</p>

<p>I came across this:
<a href="https://www.nclouds.com/blog/simplify-kubernetes-deployments-helm-part-3-creating-configmaps-secrets/" rel="noreferrer">https://www.nclouds.com/blog/simplify-kubernetes-deployments-helm-part-3-creating-configmaps-secrets/</a></p>

<p>I have the following file structure:</p>

<pre><code>/chart
  /templates
    my-config-map.yaml
  /config
    application.config
</code></pre>

<p>and my-config-map.yaml contains the following:</p>

<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: my-config
  labels:
    app: {{ template "app.prefix" . }}
data:
  {{ (tpl (.Files.Glob "config/*").AsConfig . ) | indent 2 }}
</code></pre>

<p>When I run this command:</p>

<pre><code>kubectl get configmaps my-config -n my-namespace -o yaml
</code></pre>

<p>I get:</p>

<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  creationTimestamp: 2019-07-26T11:11:05Z
  labels:
    app: my-app
  name: my-config
  namespace: my-namespace
  resourceVersion: "2697856"
  selfLink: &lt;selflink&gt;
  uid: 0fe63ba8-af96-11e9-a73e-42010af00273
</code></pre>

<p>Note that it does not appear to have any data in it.  However if I create it from the command line using this command:</p>

<pre><code>kubectl --namespace my-namespace create configmap my-config --from-file=application.conf
</code></pre>

<p>I get this, which does appear to contain the data:</p>

<pre><code>apiVersion: v1
data:
  application.conf: |-
    conf {
      ...
kind: ConfigMap
metadata:
  creationTimestamp: 2019-07-26T11:00:59Z
  name: my-config
  namespace: my-namespace
  resourceVersion: "2695174"
  selfLink: &lt;selflink&gt;
</code></pre>

<p>What exactly am I doing wrong?</p>

Andy
<h3>Background</h3>
<p>This tutorial and question is quite old (Asked 1 year, 4 months ago). The currently used version of <a href="https://helm.sh/" rel="noreferrer">Helm</a> is <code>3</code>. It does not require <code>Tiller</code>.</p>
<p>As you stated in your question, you have to use <a href="https://helm.sh/docs/chart_template_guide/accessing_files/#glob-patterns" rel="noreferrer">Glob</a> and put files into proper directories. I have tested this on my <code>GKE</code> cluster with <code>Helm3</code>.</p>
<pre><code>$ helm version
version.BuildInfo{Version:&quot;v3.2.1&quot;
</code></pre>
<h3>Solution - Steps</h3>
<p><strong>1. Create <code>test-chart</code></strong></p>
<p>I have created it in my <code>/home/user</code> directory</p>
<pre><code>$ helm create test-chart
Creating test-chart
$ ls
postgress test-chart
</code></pre>
<p><strong>2. Create directory where you will put/download file with configuration</strong></p>
<pre><code>$ cd test-chart/
$ ls
charts  Chart.yaml  templates  values.yaml
$ mkdir configmap
$ ls
charts  Chart.yaml  configmap  templates  values.yaml
$ cd configmap/
</code></pre>
<p>I have used example from <a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/" rel="noreferrer">Kubernetes docs</a>.</p>
<pre><code>
$ wget https://kubernetes.io/examples/configmap/ui.properties
...
ui.properties                               100%[===========================================================================================&gt;]      83  --.-KB/s    in 0s

2020-12-14 15:14:14 (687 KB/s) - ‘ui.properties’ saved [83/83]
...
user@cloudshell:~/test-chart/configmap (project)$ cat ui.properties
color.good=purple
color.bad=yellow
allow.textmode=true
how.nice.to.look=fairlyNice
</code></pre>
<p><strong>3. Create <code>ConfigMap</code> file in <code>templates</code> directory</strong></p>
<pre><code>$ cd ~/test-chart/templates
</code></pre>
<p>Create <code>configmap</code> yaml like below.</p>
<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: test-config
data:
  {{- (.Files.Glob &quot;configmap/*&quot;).AsConfig | nindent 2 }}
</code></pre>
<p><strong>4. Install chart / use <code>--dry-run</code></strong></p>
<p>Go to main directory <code>~/test-chart</code>, where you have files like below</p>
<pre><code>charts  Chart.yaml  configmap  templates  values.yaml
</code></pre>
<p>Now you can <code>helm install</code> chart or use <a href="https://helm.sh/docs/chart_template_guide/debugging/" rel="noreferrer">--dry-run</a> option before, to check how configuration YAMLs would looks like.</p>
<p><strong>5. Output</strong></p>
<pre><code>$ helm install test . --dry-run
NAME: test
LAST DEPLOYED: Mon Dec 14 15:24:38 2020
NAMESPACE: default
STATUS: pending-install
REVISION: 1
HOOKS:
---
# Source: test-chart/templates/tests/test-connection.yaml
...
---
# Source: test-chart/templates/configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: test-config
data:
  ui.properties: |
    color.good=purple
    color.bad=yellow
    allow.textmode=true
    how.nice.to.look=fairlyNice
---
# Source: test-chart/templates/service.yaml
</code></pre>
<h3>Conclusion</h3>
<p>File which will be base for <code>configmap</code> must be in the directory, which is on the same level as <code>template</code> directory and <code>Chart.yaml</code>. You also have to use <code>Files.Glob</code> and provide proper path to configuration file.</p>
