How to set wiredTigerCacheSize in mongodb when deployed in kubernetes

11/12/2020

I would like to set the mongodb wiredTigerCacheSize in my kubernetes deployment (linux).
In docker I could simply define:

docker run -d --name my-mongo mongo --wiredTigerCacheSizeGB 0.25

but not in kubernetes...

I have the following deployment:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-mongo
spec:
  replicas: 1
  selector:
    matchLabels:
      app: my-mongo-db
  template:
    metadata:
      labels:
        app: my-mongo-db
    spec:
      containers:
      - name: my-mongo-db
        image: mongo
        env:
        ports:
        - containerPort: 27017

so far I have tried (did not work):

lifecycle:
      postStart:
        exec:
          command: ["/bin/sh", "-c", "mongod --wiredTigerCacheSizeGB 0.25"]
-- Uri Loya
kubernetes
mongodb

1 Answer

11/16/2020

After a lot of reading (thanks to Minsky who pointed me in the right direction) I have found the following solution to work:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-mongo
spec:
  replicas: 1
  selector:
    matchLabels:
      app: my-mongo-db
  template:
    metadata:
      labels:
        app: my-mongo-db
    spec:
      containers:
      - name: my-mongo-db
        image: mongo
        command: ["docker-entrypoint.sh"]
        args: ["mongod", "--wiredTigerCacheSizeGB", "0.25"]
        env:
        ports:
        - containerPort: 27017
-- Uri Loya
Source: StackOverflow