<p>I learning about k8s and Helm so I started to create a simple flask app which uses mongondb, I have the deployment, the service and the ingress installed with helm and are working fine. For the mongo container I am using the chart from Bitnami, but I need to insert some data on creation, as I do wih the normal deployment by adding:</p>
<pre><code> volumeMounts:
   - name: mongo-initdb
   mountPath: /docker-entrypoint-initdb.d
</code></pre>
<p>In the bitnami documentation <a href="https://artifacthub.io/packages/helm/bitnami/mongodb" rel="nofollow noreferrer">https://artifacthub.io/packages/helm/bitnami/mongodb</a> it says that the data can be entered through a script or a configmap with the parameters <code>initdbScripts</code> or <code>initdbScriptsConfigMap</code> but I tried adding them like this and does not work:</p>
<pre><code>mongodb:
  metrics:
    enabled: true
  global:
    namespaceOverride: flask-app
  initdbScriptsConfigMap: mongo-initdb.yaml
</code></pre>
<p>being this the configmap which works when using K8s with .yaml files:</p>
<pre><code>apiVersion: v1
data:
  init-db.js: |-
    db = db.getSiblingDB(&quot;cars_db&quot;);
    db.car_tb.drop();

    db.car_tb.insertMany([
        {
            &quot;id&quot;: 1,
            &quot;brand&quot;: &quot;Ford&quot;,
            &quot;model&quot;: &quot;Mustang&quot;
        },
        {
            &quot;id&quot;: 2,
            &quot;brand&quot;: &quot;Lamborghini&quot;,
            &quot;model&quot;: &quot;Veneno&quot;
        },
        {
            &quot;id&quot;: 3,
            &quot;brand&quot;: &quot;Ferrari&quot;,
            &quot;model&quot;: &quot;Enzo&quot;
        },
        {
            &quot;id&quot;: 4,
            &quot;brand&quot;: &quot;Mercedes&quot;,
            &quot;model&quot;: &quot;Cls63-AMG&quot;
        },
    ]);
kind: ConfigMap
metadata:
  name: mongo-initdb
  namespace: flask-app
</code></pre>
<p>Being the mongo-configmap.yaml inside the templates folder.</p>
<p>As it does not work I have tried adding a configmap named <code>docker-entrypoint-initdb.d </code> and set it inside a folder named files as stated here <a href="https://docs.bitnami.com/kubernetes/infrastructure/mongodb/administration/initialize-instance/" rel="nofollow noreferrer">https://docs.bitnami.com/kubernetes/infrastructure/mongodb/administration/initialize-instance/</a> but none of them works and do not have any examples on the documentation.</p>
<p>EDIT
I have tried adding this to the <code>values.yaml</code>:</p>
<pre><code>mongodb:
  metrics:
    enabled: true
  global:
    namespaceOverride: flask-app
  auth:
    username: root
    password: pass
    database: cars_db
    rootPassword: pass
  initdbScripts: 
    init-db.js: |
      db = db.getSiblingDB(&quot;cars_db&quot;);
      db.car_tb.drop();

      db.car_tb.insertMany([
          {
              &quot;id&quot;: 1,
              &quot;brand&quot;: &quot;Ford&quot;,
              &quot;model&quot;: &quot;Mustang&quot;
          },
          {
              &quot;id&quot;: 2,
              &quot;brand&quot;: &quot;Lamborghini&quot;,
              &quot;model&quot;: &quot;Veneno&quot;
          },
          {
              &quot;id&quot;: 3,
              &quot;brand&quot;: &quot;Ferrari&quot;,
              &quot;model&quot;: &quot;Enzo&quot;
          },
          {
              &quot;id&quot;: 4,
              &quot;brand&quot;: &quot;Mercedes&quot;,
              &quot;model&quot;: &quot;Cls63-AMG&quot;
          },
      ]);
</code></pre>
<p>But this does not work either I got this from the official github <a href="https://github.com/bitnami/charts/blob/master/bitnami/mongodb/values.yaml" rel="nofollow noreferrer">https://github.com/bitnami/charts/blob/master/bitnami/mongodb/values.yaml</a> but I do not get how to make it work from the documentation and I cannot get any examples anywhere I have looked for</p>

Jesus Fernandez
<p>You've probably figured this out by now, because you were close.  I was able to do what you're looking to do using the following in my parent Chart's <code>values.yaml</code>:</p>
<pre><code>mongodb:
  initdbScripts:
    my_init_script.js: |
      db = db.getSiblingDB(&quot;cars_db&quot;);
      db.car_tb.drop();

      db.car_tb.insertMany([
          {
              &quot;id&quot;: 1,
              &quot;brand&quot;: &quot;Ford&quot;,
              &quot;model&quot;: &quot;Mustang&quot;
          },
          {
              &quot;id&quot;: 2,
              &quot;brand&quot;: &quot;Lamborghini&quot;,
              &quot;model&quot;: &quot;Veneno&quot;
          },
          {
              &quot;id&quot;: 3,
              &quot;brand&quot;: &quot;Ferrari&quot;,
              &quot;model&quot;: &quot;Enzo&quot;
          },
          {
              &quot;id&quot;: 4,
              &quot;brand&quot;: &quot;Mercedes&quot;,
              &quot;model&quot;: &quot;Cls63-AMG&quot;
          },
      ]);
</code></pre>
<p>The important part is that this is within my parent chart's <code>values.yaml</code>.  If you're modifying the mongodb chart directly (you probably shouldn't but whatever), omit the <code>mongodb</code> part and out-dent the rest.  That's only necessary to override a child chart's values.</p>
<p>Also worth noting that I haven't tried this with the un/db/password overrides you're using, so maybe try removing those?</p>
<p>One other thing it could be is that there's a bugged version of the Bitnami mongo charts in which they straight up forgot to execute the <em>.js/</em>.sh files at startup so nothing happens.  Try updating your chart version.  I did this using:</p>
<pre><code>- name: mongodb
  version: &quot;10.15.0&quot;
  repository: https://charts.bitnami.com/bitnami
</code></pre>
