简体   繁体   English

Kubernetes杀害Mongo容器

[英]Kubernetes Killing Mongo Container

We have a situation where Kubernetes is killing Mongo containers when it reaches max memory limit of the container. 我们有一种情况,Kubernetes在达到容器的最大内存限制时会杀死Mongo容器。 Even though its expected to K8s to work in that way but feel like Mongo is not reusing its memory as its keep on growing the memory usage day by day even though the user load & transactions are the same so what to check how we can limit the Mongo in reaching max memory of the container or flush Mongo memory at regular intervals. 虽然它预计K8会以这种方式工作,但感觉Mongo并没有重复使用它的内存,因为它不断增加内存使用量,即使用户负载和交易是相同的,那么如何检查我们如何限制Mongo达到容器的最大内存或定期刷新Mongo内存。

I have tried to increase the memory which helped the pods to keep running a couple of more days before K8 killing it 我试图增加内存,这有助于pod在K8杀死它之前继续运行几天

     "containers": [
          {
            "name": "mongo",
            "image": "dockercentral.com:5870/com.public/mongodb:3.6",
            "ports": [
              {
                "containerPort": 27017,
                "protocol": "TCP"
              }
            ]      
"resources": {
              "limits": {
                "cpu": "1",
                "memory": "24Gi"
              },
              "requests": {
                "cpu": "250m",
                "memory": "24Gi"
              }
            }
   "name": "MONGO_SECURITY",
                "value": "true"
              }
            ],
            "resources": {
              "limits": {
                "cpu": "500m",
                "memory": "1Gi"
              },
              "requests": {
                "cpu": "150m",
                "memory": "256Mi"
              }
            },

Based on what Stennie from MongoDB, Inc. wrote in comment to question. 基于MongoDB,Inc。的Stennie在评论中写道。

this command in kube .yaml works for me: kube .yaml中的这个命令对我有用:

      command:
        - "sh"
        - "-c"
        - >
          echo "storage:" >>  /etc/mongod.conf;
          echo "    wiredTiger:" >>  /etc/mongod.conf;
          echo "       engineConfig:" >>  /etc/mongod.conf;
          echo "          cacheSizeGB: 2" >>  /etc/mongod.conf;
          echo "replication:" >> /etc/mongod.conf;
          echo "  replSetName: YOUR_REPL_NAME" >> /etc/mongod.conf;
          mongod --config /etc/mongod.conf;

also there is a way to set it in runtime: 还有一种方法可以在运行时设置它:

db.adminCommand( { "setParameter": 1, "wiredTigerEngineRuntimeConfig":"cache_size=2G"})

which also works just fine, but it looks easier through kuberneties yaml file because to issue a command you have to wait until mongo is up and running. 这也很好,但通过kuberneties yaml文件看起来更容易,因为要发出命令,你必须等到mongo启动并运行。

NOTE: make sure that your: 注意:确保您的:

      resources:
        limits:
          memory:

is allowing extra 1G for system. 系统允许额外的1G

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM