how to use the inid-db script or configmap in the mongodb chart in Helm?

801 views
Skip to first unread message

jesus fernandez

unread,
Feb 18, 2021, 5:44:59 AM2/18/21
to Helm Developers
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:
```
 volumeMounts:
   - name: mongo-initdb
   mountPath: /docker-entrypoint-initdb.d
```
In the bitnami documentation https://artifacthub.io/packages/helm/bitnami/mongodb it says that the data can be entered through a script or a configmap with the parameters ```initdbScripts``` or ```initdbScriptsConfigMap``` but I tried adding them like this and does not work:
```
mongodb:
  metrics:
    enabled: true
  global:
    namespaceOverride: flask-app
  initdbScriptsConfigMap: mongo-configmap.yaml
```
being this the configmap which works when using K8s with .yaml files:
```
apiVersion: v1
data:
  init-db.js: |-
    db = db.getSiblingDB("cars_db");
    db.car_tb.drop();

    db.car_tb.insertMany([
        {
            "id": 1,
            "brand": "Ford",
            "model": "Mustang"
        },
        {
            "id": 2,
            "brand": "Lamborghini",
            "model": "Veneno"
        },
        {
            "id": 3,
            "brand": "Ferrari",
            "model": "Enzo"
        },
        {
            "id": 4,
            "brand": "Mercedes",
            "model": "Cls63-AMG"
        },
    ]);
kind: ConfigMap
metadata:
  name: mongo-initdb
  namespace: flask-app
```
Being the mongo-configmap.yaml inside the templates folder. As it does not work I have tried adding a configmap named ```docker-entrypoint-initdb.d ``` and det it inside a folder named files as stated here https://docs.bitnami.com/kubernetes/infrastructure/mongodb/administration/initialize-instance/ but none of them works and do not have any examples on the documentation. Could someone provide with some examples on how it has to be used? Thanks!
Reply all
Reply to author
Forward
0 new messages