解析命令行时出错:无法识别的选项“--wiredTigerCacheSizeGB 2”

Error parsing command line: unrecognised option '--wiredTigerCacheSizeGB 2'

我有一个 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

如果删除 --wiredTigerCacheSizeGB 标志是否有效?

我会很惊讶。

It does appear to work (see below) but I can't explain why. I am surprised!

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

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

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

NOTE The inclusion of = between the flag and value to avoid introducing YAML parsing issues.

我使用 podman 测试了这个假设;如果您使用 docker:

,您可以在下面的内容中将 podman 替换为 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