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-initdb.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 set 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.
EDIT
I have tried adding this to the values.yaml:
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("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"
},
]);
But this does not work either I got this from the official github https://github.com/bitnami/charts/blob/master/bitnami/mongodb/values.yaml but I do not get how to make it work from the documentation and I cannot get any examples anywhere I have looked for