I have a Google Kubernetes Engine running and I'm trying to deploy a mongo container. Everything works fine except when I try to use the argument "--wiredTigerCacheSizeGB", then the deployment fails because this command is not recognized. I'm using the latest Mongo version (5.0) and I see nothing in the documentation saying that this should not work.
Here is the yml configuration of the POD creation:
apiVersion: apps/v1
kind: StatefulSet
spec:
podManagementPolicy: OrderedReady
replicas: 1
revisionHistoryLimit: 10
selector:
matchLabels:
environment: test
role: mongo
serviceName: mongo
template:
metadata:
creationTimestamp: null
labels:
environment: test
role: mongo
namespace: default
spec:
containers:
- command:
- mongod
- --wiredTigerCacheSizeGB 2
image: mongo:5.0
imagePullPolicy: Always
name: mongo
ports:
- containerPort: 27017
protocol: TCP
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
- mountPath: /data/db
name: mongo-persistent-storage
dnsPolicy: ClusterFirst
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 10
tolerations:
- effect: NoSchedule
key: dedicated
operator: Equal
value: backend
updateStrategy:
type: OnDelete
volumeClaimTemplates:
- apiVersion: v1
kind: PersistentVolumeClaim
metadata:
annotations:
volume.beta.kubernetes.io/storage-class: standard
creationTimestamp: null
name: mongo-persistent-storage
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 20Gi
volumeMode: Filesystem
CodePudding user response:
Does it work if you remove the --wiredTigerCacheSizeGB
flag?
I would be surprised.
It does appear to work (see below) but I can't explain why. I am surprised!
If this is the correct Dockerfile for the image, then it uses a Docker CMD
to run mongod
.
If so, you'd need to run the image on Kubernetes using args
not command
in order to correctly override the container image's CMD
and not override the container image's ENTRYPOINT
, i.e.
containers:
- name: mongo
args:
- mongod
- --wiredTigerCacheSizeGB=2
NOTE The inclusion of
=
between the flag and value to avoid introducing YAML parsing issues.
I tested this hypothesis using podman
; you can replace podman
with docker
in what follows if you use docker
:
# Does not work: Override `ENTRYPOINT` with mongod flag
# This is effectively what you're doing
podman run \
--interactive --tty --rm \
--entrypoint="mongod --wiredTigerCacheSizeGB=2" \
docker.io/mongo:5.0 \
Error: executable file `mongod --wiredTigerCacheSizeGB=2` not found in $PATH:
No such file or directory:
OCI runtime attempted to invoke a command that was not found
# Works: Override `CMD`
# This is what I thought should work
podman run \
--interactive --tty --rm \
docker.io/mongo:5.0 \
mongod \
--wiredTigerCacheSizeGB=2
# Works: Override `ENTRYPOINT` w/ mongod
# This is what I thought wouldn't work
podman run \
--interactive --tty --rm \
--entrypoint=mongod \
docker.io/mongo:5.0 \
--wiredTigerCacheSizeGB=2
CodePudding user response:
By default Mongo will set the wiredTigerCacheSizeGB
to a value proportional to the host's total memory regardless of memory limits you may have imposed on the container. In such an instance you will want to set the cache size to something appropriate, taking into account any other processes you may be running in the container which would also utilize memory.
Taking the examples above you can configure the cache size to use 1.5GB as:
$ docker run --name some-mongo -d mongo --wiredTigerCacheSizeGB 1.5