Skip to main content
Version: Preview

Configure cluster parameters

This guide shows how to configure cluster parameters.

Before you start

  1. Install KubeBlocks.
  2. Create a MongoDB cluster.

Configure cluster parameters by configuration file

  1. Get the configuration file of this cluster.

    kubectl edit configurations.apps.kubeblocks.io mycluster-mongodb -n demo
  2. Configure parameters according to your needs. The example below adds the spec.configFileParams part to configure systemLog.verbosity.

    spec:
    clusterRef: mycluster
    componentName: mongodb
    configItemDetails:
    - configFileParams:
    mongodb.cnf:
    parameters:
    systemLog.verbosity: "1"
    configSpec:
    constraintRef: mongodb-config-constraints
    name: mongodb-configuration
    namespace: kb-system
    templateRef: mongodb5.0-config-template
    volumeName: mongodb-config
    name: mongodb-config
    - configSpec:
    defaultMode: 292
  3. Connect to this cluster to verify whether the configuration takes effect as expected.

    kubectl exec -ti -n demo mycluster-mongodb-0 -- bash

    root@mycluster-mongodb-0:/# cat etc/mongodb/mongodb.conf |grep verbosity
    >
    verbosity: 1

Configure cluster parameters with OpsRequest

  1. Define an OpsRequest file and configure the parameters in the OpsRequest in a yaml file named mycluster-configuring-demo.yaml. In this example, systemLog.verbosity is configured as 1.

    apiVersion: apps.kubeblocks.io/v1alpha1
    kind: OpsRequest
    metadata:
    name: mycluster-configuring-demo
    namespace: demo
    spec:
    clusterName: mycluster
    reconfigure:
    componentName: mongodb
    configurations:
    - keys:
    - key: mongodb.conf
    parameters:
    - key: systemLog.verbosity
    value: "1"
    name: mongodb-config
    preConditionDeadlineSeconds: 0
    type: Reconfiguring
    FieldDefinition
    metadata.nameIt specifies the name of this OpsRequest.
    metadata.namespaceIt specifies the namespace where this cluster is created.
    spec.clusterNameIt specifies the cluster name that this operation is targeted at.
    spec.reconfigureIt specifies a component and its configuration updates.
    spec.reconfigure.componentNameIt specifies the component name of this cluster.
    spec.configurationsIt contains a list of ConfigurationItem objects, specifying the component's configuration template name, upgrade policy, and parameter key-value pairs to be updated.
    spec.reconfigure.configurations.keys.keyIt specifies the configuration map.
    spec.reconfigure.configurations.keys.parametersIt defines a list of key-value pairs for a single configuration file.
    spec.reconfigure.configurations.keys.parameter.keyIt represents the name of the parameter you want to edit.
    spec.reconfigure.configurations.keys.parameter.valueIt represents the parameter values that are to be updated. If set to nil, the parameter defined by the Key field will be removed from the configuration file.
    spec.reconfigure.configurations.nameIt specifies the configuration template name.
    preConditionDeadlineSecondsIt specifies the maximum number of seconds this OpsRequest will wait for its start conditions to be met before aborting. If set to 0 (default), the start conditions must be met immediately for the OpsRequest to proceed.
  2. Apply the configuration opsRequest.

    kubectl apply -f mycluster-configuring-demo.yaml
  3. Connect to this cluster to verify whether the configuration takes effect as expected.

    kubectl exec -ti -n demo mycluster-mongodb-0 -- bash

    root@mycluster-mongodb-0:/# cat etc/mongodb/mongodb.conf |grep verbosity
    >
    verbosity: 1
note

Just in case you cannot find the configuration file of your cluster, you can use kbcli to view the current configuration file of a cluster.

kbcli cluster describe-config mycluster -n demo

From the meta information, the cluster mycluster has a configuration file named mongodb.conf.

You can also view the details of this configuration file and parameters.

  • View the details of the current configuration file.

    kbcli cluster describe-config mycluster --show-detail -n demo
  • View the parameter description.

    kbcli cluster explain-config mycluster -n demo | head -n 20
  • View the user guide of a specified parameter.

    kbcli cluster explain-config mycluster --param=systemLog.verbosity --config-specs=mongodb-config -n demo

    --config-specs is required to specify a configuration template since ApeCloud MySQL currently supports multiple templates. You can run kbcli cluster describe-config mycluster to view the all template names.

    Output
    template meta:
    ConfigSpec: mongodb-config ComponentName: mongodb ClusterName: mycluster

    Configure Constraint:
    Parameter Name: systemLog.verbosity
    Allowed Values: [0-5]
    Scope: Global
    Dynamic: false
    Type: integer
    Description:
    • Allowed Values: It defines the valid value range of this parameter.
    • Dynamic: The value of Dynamic in Configure Constraint defines how the parameter configuration takes effect. There are two different configuration strategies based on the effectiveness type of modified parameters, i.e. dynamic and static.
      • When Dynamic is true, it means the effectiveness type of parameters is dynamic and can be configured online.
      • When Dynamic is false, it means the effectiveness type of parameters is static and a pod restarting is required to make the configuration effective.
    • Description: It describes the parameter definition.