【问题标题】:Error parsing command line: unrecognised option '--wiredTigerCacheSizeGB 2'解析命令行时出错:无法识别的选项“--wiredTigerCacheSizeGB 2”
【发布时间】:2021-11-02 19:27:33
【问题描述】:

我正在运行一个 Google Kubernetes Engine,我正在尝试部署一个 mongo 容器。一切正常,除非我尝试使用参数“--wiredTigerCacheSizeGB”,然后部署失败,因为无法识别此命令。我正在使用最新的 Mongo 版本 (5.0),但我在文档中没有看到任何内容表明这不起作用。

这里是创建POD的yml配置:

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

【问题讨论】:

    标签: mongodb kubernetes google-kubernetes-engine


    【解决方案1】:

    如果你去掉--wiredTigerCacheSizeGB标志,它会起作用吗?

    我会感到惊讶。

    它似乎确实有效(见下文),但我无法解释原因。我很惊讶!

    如果这是映像的正确 Dockerfile,则它使用 Docker CMD 运行 mongod

    如果是这样,您需要使用 args 而不是 command 在 Kubernetes 上运行映像,以便正确覆盖容器映像的 CMD 并且 覆盖容器映像的 @987654328 @,即

    containers:
    - name: mongo
      args:
      - mongod
      - --wiredTigerCacheSizeGB=2
    

    注意在标志和值之间包含 = 以避免引入 YAML 解析问题。

    我使用podman 测试了这个假设;如果你使用docker,你可以在下面用docker替换podman

    # 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
    

    【讨论】:

    • 谢谢,args 完成了这项工作
    猜你喜欢
    • 2018-06-07
    • 2016-07-21
    • 2015-11-12
    • 2021-08-21
    • 2020-10-06
    • 1970-01-01
    • 1970-01-01
    • 2021-01-28
    • 2021-08-05
    相关资源
    最近更新 更多