Skip to content
logo
Percona Operator for MongoDB
Changing MongoDB options
Initializing search
    percona/k8spsmdb-docs
    percona/k8spsmdb-docs
    • Welcome
      • System requirements
      • Design and architecture
      • Comparison with other solutions
      • Install with Helm
      • Install with kubectl
      • Install on Minikube
      • Install on Google Kubernetes Engine (GKE)
      • Install on Amazon Elastic Kubernetes Service (AWS EKS)
      • Install on Microsoft Azure Kubernetes Service (AKS)
      • Generic Kubernetes installation
      • Install on OpenShift
      • Application and system users
      • Changing MongoDB options
        • Edit the deploy/cr.yaml file
        • Use a ConfigMap
        • Use a Secret Object
      • Anti-affinity and tolerations
      • Labels and annotations
      • Exposing the cluster
      • Local storage support
      • Arbiter and non-voting nodes
      • MongoDB sharding
      • Transport encryption (TLS/SSL)
      • Data at rest encryption
      • Telemetry
        • About backups
        • Configure storage for backups
        • Making scheduled backups
        • Making on-demand backup
        • Storing operations logs for point-in-time recovery
        • Restore from a previously saved backup
        • Delete the unneeded backup
      • Upgrade MongoDB and the Operator
      • Horizontal and vertical scaling
      • Multi-cluster and multi-region deployment
      • Monitor with Percona Monitoring and Management (PMM)
      • Add sidecar containers
      • Restart or pause the cluster
      • Debug and troubleshoot
      • OpenLDAP integration
      • How to use private registry
      • Creating a private S3-compatible cloud for backups
      • Restore backup to a new Kubernetes-based environment
      • How to use backups to move the external database to Kubernetes
      • Install Percona Server for MongoDB in multi-namespace (cluster-wide) mode
      • Upgrading Percona Server for MongoDB manually
      • Custom Resource options
      • Percona certified images
      • Operator API
      • Frequently asked questions
      • Old releases (documentation archive)
      • Release notes index
      • Percona Operator for MongoDB 1.14.0 (2023-03-13)
      • Percona Operator for MongoDB 1.13.0 (2022-09-15)
      • Percona Operator for MongoDB 1.12.0 (2022-05-05)
      • Percona Distribution for MongoDB Operator 1.11.0 (2021-12-21)
      • Percona Distribution for MongoDB Operator 1.10.0 (2021-09-30)
      • Percona Distribution for MongoDB Operator 1.9.0 (2021-07-29)
      • Percona Kubernetes Operator for Percona Server for MongoDB 1.8.0 (2021-05-06)
      • Percona Kubernetes Operator for Percona Server for MongoDB 1.7.0 (2021-03-08)
      • Percona Kubernetes Operator for Percona Server for MongoDB 1.6.0 (2020-12-22)
      • Percona Kubernetes Operator for Percona Server for MongoDB 1.5.0 (2020-09-07)
      • Percona Kubernetes Operator for Percona Server for MongoDB 1.4.0 (2020-03-31)
      • Percona Kubernetes Operator for Percona Server for MongoDB 1.3.0 (2019-12-11)
      • Percona Kubernetes Operator for Percona Server for MongoDB 1.2.0 (2019-09-20)
      • Percona Kubernetes Operator for Percona Server for MongoDB 1.1.0 (2019-07-15)
      • Percona Kubernetes Operator for Percona Server for MongoDB 1.0.0 (2019-05-29)

    • Edit the deploy/cr.yaml file
    • Use a ConfigMap
    • Use a Secret Object

    Changing MongoDB Options¶

    You may require a configuration change for your application. MongoDB allows configuring the database with a configuration file, as many other database management systems do. You can pass options to MongoDB instances in the cluster in one of the following ways:

    • edit the deploy/cr.yaml file,
    • use a ConfigMap,
    • use a Secret object.

    You can pass configuration settings separately for mongod Pods, mongos Pods, and Config Server Pods.

    Edit the deploy/cr.yaml file¶

    You can add MongoDB configuration options to the replsets.configuration, sharding.mongos.configuration, and sharding-configsvrreplset-configuration keys of the deploy/cr.yaml. Here is an example:

    spec:
      ...
      replsets:
        - name: rs0
          size: 3
          configuration: |
            operationProfiling:
              mode: slowOp
            systemLog:
              verbosity: 1
          ...
    

    See the official manual for the complete list of options, as well as specific Percona Server for MongoDB documentation pages.

    Use a ConfigMap¶

    You can use a ConfigMap and the cluster restart to reset configuration options. A ConfigMap allows Kubernetes to pass or update configuration data inside a containerized application.

    You should give the ConfigMap a specific name, which is composed of your cluster name and a specific suffix:

    • my-cluster-name-rs0-mongod for the Replica Set (mongod) Pods,
    • my-cluster-name-cfg-mongod for the Config Server Pods,
    • my-cluster-name-mongos for the mongos Pods,

    Note

    To find the cluster name, you can use the following command:

    $ kubectl get psmdb
    

    For example, let’s define a mongod.conf configuration file and put there several MongoDB options we used in the previous example:

    operationProfiling:
      mode: slowOp
    systemLog:
      verbosity: 1
    

    You can create a ConfigMap from the mongod.conf file with the kubectl create configmap command. It has the following syntax:

    $ kubectl create configmap <configmap-name> <resource-type=resource-name>
    

    The following example defines my-cluster-name-rs0-mongod as the ConfigMap name and the mongod.conf file as the data source:

    $ kubectl create configmap my-cluster-name-rs0-mongod --from-file=mongod.conf=mongod.conf
    

    To view the created ConfigMap, use the following command:

    $ kubectl describe configmaps my-cluster-name-rs0-mongod
    

    Note

    Do not forget to restart Percona Server for MongoDB to ensure the cluster has updated the configuration (see details on how to connect in the Install Percona Server for MongoDB on Kubernetes page).

    Use a Secret Object¶

    The Operator can also store configuration options in Kubernetes Secrets. This can be useful if you need additional protection for some sensitive data.

    You should create a Secret object with a specific name, composed of your cluster name and a specific suffix:

    • my-cluster-name-rs0-mongod for the Replica Set Pods,
    • my-cluster-name-cfg-mongod for the Config Server Pods,
    • my-cluster-name-mongos for the mongos Pods,

    Note

    To find the cluster name, you can use the following command:

    $ kubectl get psmdb
    

    Configuration options should be put inside a specific key:

    • data.mongod key for Replica Set (mongod) and Config Server Pods,
    • data.mongos key for mongos Pods.

    Actual options should be encoded with Base64.

    For example, let’s define a mongod.conf configuration file and put there several MongoDB options we used in the previous example:

    operationProfiling:
      mode: slowOp
    systemLog:
      verbosity: 1
    

    You can get a Base64 encoded string from your options via the command line as follows:

    $ cat mongod.conf | base64 --wrap=0
    
    $ cat mongod.conf | base64
    

    Note

    Similarly, you can read the list of options from a Base64 encoded string:

    $ echo "ICAgICAgb3BlcmF0aW9uUHJvZmlsaW5nOgogICAgICAgIG1vZGU6IHNsb3dPc\
    AogICAgICBzeXN0ZW1Mb2c6CiAgICAgICAgdmVyYm9zaXR5OiAxCg==" | base64 --decode
    

    Finally, use a yaml file to create the Secret object. For example, you can create a deploy/my-mongod-secret.yaml file with the following contents:

    apiVersion: v1
    kind: Secret
    metadata:
      name: my-cluster-name-rs0-mongod
    data:
      mongod.conf: "ICAgICAgb3BlcmF0aW9uUHJvZmlsaW5nOgogICAgICAgIG1vZGU6IHNsb3dPc\
       AogICAgICBzeXN0ZW1Mb2c6CiAgICAgICAgdmVyYm9zaXR5OiAxCg=="
    

    When ready, apply it with the following command:

    $ kubectl create -f deploy/my-mongod-secret.yaml
    

    Note

    Do not forget to restart Percona Server for MongoDB to ensure the cluster has updated the configuration (see details on how to connect in the Install Percona Server for MongoDB on Kubernetes page).

    Contact Us

    For free technical help, visit the Percona Community Forum.

    To report bugs or submit feature requests, open a JIRA ticket.

    For paid support and managed or consulting services , contact Percona Sales.


    Last update: 2023-03-14
    Percona LLC and/or its affiliates, © 2009 - 2023
    Made with Material for MkDocs

    Cookie consent

    We use cookies to recognize your repeated visits and preferences, as well as to measure the effectiveness of our documentation and whether users find what they're searching for. With your consent, you're helping us to make our documentation better.