I tried to run Mongodb on Kubernetes. However it always got Evicted every 1-2 minutes. I tried to run the image in docker and worked fine. Do I need to make special configuration?
deployment file
apiVersion: apps/v1
kind: Deployment
metadata:
name: mongodb1
namespace: xxxxx
labels:
app: mongodb1
env: dev1
spec:
replicas: 1
selector:
matchLabels:
app: mongodb1
env: dev1
template:
metadata:
labels:
app: mongodb1
env: dev1
spec:
containers:
- name: mongodb1
image: xxxx/mongo:1.0
ports:
- containerPort: 27017
env:
- name: TZ
value: Asis/Bangkok
- name: MONGO_INITDB_DATABASE
value: blockchaindb
tty: true
stdin: true
resources:
limits:
cpu: 500m
memory: 2Gi
requests:
cpu: 500m
memory: 2Gi
imagePullSecrets:
- name: xxxx
I tried to use the config file and rename the image name. So, I created a Dockerfile. Here is my DockerFile.
FROM mongo:latest
MAINTAINER TEST
COPY ./mongo-init.js /docker-entrypoint-initdb.d/mongo-init.js
COPY ./mongod.conf /etc/mongod.conf
RUN mkdir /var/lib/mongodb
RUN mongod --fork --logpath /var/log/mongodb.log --dbpath /var/lib/mongodb \
&& CREATE_FILES=/docker-entrypoint-initdb.d/* \
&& for f in $CREATE_FILES; do mongo 127.0.0.1:27017 $f; done \
&& mongod --dbpath /var/lib/mongodb --shutdown \
&& chown -R mongodb /var/lib/mongodb
CMD mongod --config /etc/mongod.conf
I set up wiredTigerCacheSize to 512M, but the logs still show systemMemorySize 60G.
cache_size=512M
{"t":{"$date":"2021-02-18T02:25:08.651+00:00"},"s":"I", "c":"STORAGE", "id":22315, "ctx":"initandlisten","msg":"Opening WiredTiger","attr":{"config":"create,cache_size=512M,session_max=33000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000,close_scan_interval=10,close_handle_minimum=250),statistics_log=(wait=0),verbose=[recovery_progress,checkpoint_progress,compact_progress],"}}
Logs "systemMemSizeMB":64380
{"t":{"$date":"2021-02-18T02:25:08.648+00:00"},"s":"W", "c":"CONTROL", "id":20720, "ctx":"initandlisten","msg":"Available memory is less than system memory","attr":{"availableMemSizeMB":2048,"systemMemSizeMB":64380}}