对于 AI 代理:可在 https://www.mongodb.com/zh-cn/docs/llms.txt 获取文档索引—通过在任何 URL 路径后添加 .md 可获取所有页面的 Markdown 版本。
Docs 菜单

修改 Ops Manager 或 MongoDB Kubernetes 资源容器

You can modify the containers in the Pods in which Ops Manager and MongoDB database resources run using the template or podTemplate setting that applies to your deployment:

要查看哪些字段可以添加到 templatepodTemplate,请参阅Kubernetes文档。

当您使用templatepodTemplate创建container时,Kubernetes 操作符会根据您为containers数组中每个container提供的name以不同方式处理container创建:

  • If the name field matches the name of the applicable resource image, the Kubernetes Operator updates the Ops Manager or MongoDB database container in the Pod to which the template or podTemplate applies:

    • Ops Manager: mongodb-kubernetes-ops-manager

    • Backup Daemon Service: mongodb-backup-daemon

    • MongoDB database: mongodb-enterprise-database

    • 应用程序数据库: mongodb-kubernetes-appdb

  • If the name field does not match the name of the applicable resource image, the Kubernetes Operator creates a new container in each Pod to which the template or podTemplate applies.

On-disk files in containers in Pods don't survive container crashes or restarts. Using the spec.podSpec.podTemplate setting, you can add a volume mount to persist data in a MongoDB database resource for the life of the Pod.

要为 MongoDB database 资源创建卷挂载,请执行以下操作:

  1. 更新 MongoDB database 资源定义,以包含 Kubernetes Operator 创建的 database Pod 中的 container 的卷挂载。

    例子

    使用spec.podSpec.podTemplate定义卷挂载:

    podSpec:
    podTemplate:
    spec:
    containers:
    - name: mongodb-enterprise-database
    volumeMounts:
    - mountPath: </new/mount/path>
    name: survives-restart
    volumes:
    - name: survives-restart
    emptyDir: {}
  2. 应用更新的资源定义:

    kubectl apply -f <database-resource-conf>.yaml -n <metadata.namespace>

MongoDB 资源 Docker 映像在 RHEL 上运行并使用 RHEL 的默认系统配置。 要调整MongoDB 资源容器中的底层 RHEL 系统配置,请添加特权 InitContainer 初始化容器 使用以下设置之一:

例子

MongoDB database 资源 Docker 映像使用 RHEL 默认keepalive时间7200 。对于数据库部署,MongoDB 建议缩短keepalive120 时间。

如果在客户端与数据库资源之间的通信中遇到网络超时或套接字错误,您可以调整数据库资源 Docker 映像中的keepalive时间。

要为 MongoDB database container 调整 Docker 映像,请执行以下操作:

  1. 更新 MongoDB database 资源定义,将特权 InitContainer 附加到 Kubernetes Operator 创建的数据库 pods。

    例子

    spec.podSpec.podTemplate keepalive值更改为120的推荐值:

    spec:
    podSpec:
    podTemplate:
    spec:
    initContainers:
    - name: "adjust-tcp-keepalive"
    image: "busybox:latest"
    securityContext:
    privileged: true
    command: ["sysctl", "-w", "net.ipv4.tcp_keepalive_time=120"]
  2. 应用更新的资源定义:

    kubectl apply -f <database-resource-conf>.yaml -n <metadata.namespace>

Kubernetes adds a privileged InitContainer to each Pod that the Kubernetes Operator creates using the MongoDB resource definition.

打开与数据库资源shell Pod 中正在运行的容器的 会话 并验证您的更改。

例子

要遵循前面的keepalive示例,请调用以下命令以获取当前的keepalive值:

> kubectl exec -n <metadata.namespace> -it <pod-name> -- cat /proc/sys/net/ipv4/tcp_keepalive_time
> 120

提示

MongoDB 手册中的操作系统配置

您可以修改 MongoDB Dockerfile 模板,以创建适合您的使用案例的自定义 Kubernetes 操作符映像。要构建自定义映像,您需要:

  • 从 MongoDB 模板修改而来的自定义 Dockerfile。

  • MongoDB 为模板提供的上下文映像。

用于构建容器映像的 Dockerfile 可从MongoDB Kubernetes Github存储库公开获取。

Dockerfile 目录按资源名称、版本和分布进行组织:

├── <resource name>
│ └── <image version>
│ └── <base distribution>
│ └── Dockerfile template

将要使用的模板复制到自己的 Dockerfile 中,并根据需要进行修改。

要从任何 MongoDB Dockerfile 模板构建映像,您必须提供其上下文映像。

Each Dockerfile template has one associated context image, retrievable from the same Quay registry as the original images. Context image are always tagged in the format quay.io/mongodb/<resource-name>:<image-version>-context.

要向docker build提供上下文图像,请包含--build-arg选项,并将imagebase变量设置为 Quay.io 标签,其中<resource-name><image-version>与您的 Dockerfile 模板匹配。

例子

如果您想为任何发行版构建mongodb-enterprise-database版本 2.0.0 映像,请包括:

--build-arg imagebase=quay.io/mongodb/mongodb-kubernetes-database:2.0.0-context

默认情况下, mongodb-kubernetes-operator版本 1.9.1 的 Ubuntu 发行版基于ubuntu:1604 。 在此示例中,该基本 Dockerfile 模板已修改为使用ubuntu:1804并保存为myDockerfile

以下命令可构建自定义映像并为其赋予标签1.9.1-ubuntu-1804

cat myDockerfile | docker build --build-arg imagebase=quay.io/mongodb/mongodb-kubernetes-operator:1.9.1-context \
--tag mongodb-kubernetes-operator:1.9.1-ubuntu-1804 -

注意

docker build末尾包含连字符 ( - ) 以读取cat myDockerfile的输出,而不是提供本地目录作为构建上下文。

提示

要学习;了解有关 docker build 的详情,请参阅Docker文档。