Navigation

Install MongoDB Enterprise Kubernetes Operator

Added in Ops Manager 4.0

You can use Kubernetes to deploy MongoDB instances with Ops Manager version 4.0 or later.

MongoDB Enterprise Kubernetes Operator allows you to deploy MongoDB deployment items with Kubernetes and Ops Manager from a macOS or Linux host. This Operator uses Kubernetes and Ops Manager API methods to deploy standalone, replica set, and sharded cluster deployments that Ops Manager manages.

Note

This tutorial presumes some knowledge of Kubernetes, but does link to relevant Kubernetes documentation where possible. If you are unfamiliar with Kubernetes, please review that documentation first.

Prerequisites

To install the MongoDB Enterprise Kubernetes Operator, you must:

  1. Have a Kubernetes solution available to use.

    If you need a Kubernetes solution, see the Kubernetes documentation on picking the right solution.

  2. Clone the MongoDB Enterprise Kubernetes Operator repository.

    Note

    You can use Helm to install the Kubernetes Operator. To learn how to install Helm, see its documentation on GitHub

  3. Have or create an Ops Manager Project.

  4. Have or generate a Public API Key.

  5. Add the IP or CIDR block of any hosts that serve the Kubernetes Operator to the API Whitelist.

Considerations

Kubernetes Compatibility

MongoDB Enterprise Kubernetes Operator is compatible with Kubernetes v1.9 or later.

Install the MongoDB Enterprise Kubernetes Operator

  1. Change to the directory in which you cloned the repository.

  2. Invoke the following kubectl command:

    kubectl apply -f mongodb-enterprise.yaml -n <metadata.namespace>
    

    Important

    Always specify a namespace. Add the -n option to the kubectl apply command to specify a namespace. If you do not install the Kubernetes Operator with a namespace, the Kubernetes Operator runs in the default namespace. The Kubernetes Operator, ConfigMap, secret, and MongoDB Kubernetes resources should run in the same unique namespace.

  1. Install Helm following the instructions on GitHub

  2. Change to the directory in which you cloned the repository.

  3. Invoke the following Helm command:

    helm install helm_chart/ --name mongodb-enterprise
    

Before continuing, install Helm following the instructions on GitHub

To install the Kubernetes Operator on a host not connected to the Internet, you have two options, you can download the Kubernetes Operator files from either:

  1. Connect to the Internet.

  2. Use docker to request the files.

    docker pull quay.io/mongodb/mongodb-enterprise-operator:0.1; \
    docker pull quay.io/mongodb/mongodb-enterprise-database:0.1
    
  3. Disconnect from the Internet.

  4. Install the Kubernetes Operator with modified pull policy values.

    helm install helm_chart/ --name mongodb-enterprise \
      --set database.pullPolicy=IfNotPresent \
      --set operator.pullPolicy=IfNotPresent
    
  1. Use docker to request the files on a host connected to the Internet.

    docker pull quay.io/mongodb/mongodb-enterprise-operator:0.1; \
    docker pull quay.io/mongodb/mongodb-enterprise-database:0.1
    
  2. Save the Operator files to transferrable files.

    docker save quay.io/mongodb/mongodb-enterprise-operator:0.1 -o mongodb-enterprise-operator.tar; \
    docker save quay.io/mongodb/mongodb-enterprise-database:0.1 -o mongodb-enterprise-database.tar
    
  3. Copy these .tar files to the host running the Kubernetes docker daemon.

  4. Import the .tar files into docker.

    docker import mongodb-enterprise-operator.tar quay.io/mongodb/mongodb-enterprise-operator:0.1; \
    docker import mongodb-enterprise-database.tar quay.io/mongodb/mongodb-enterprise-database:0.1
    
  5. Install the Kubernetes Operator with modified pull policy values.

    helm install helm_chart/ --name mongodb-enterprise \
      --set database.pullPolicy=IfNotPresent \
      --set operator.pullPolicy=IfNotPresent
    

Create Credentials

For the Kubernetes Operator to create or update objects in your Ops Manager Project, you need to store your username and Public API Key as a Kubernetes secret. Creating a secret stores authentication credentials so only Kubernetes can access them.

Multiple secrets can exist in the same namespace. Each user should have their own secret.

To create your Kubernetes secret:

  1. Make sure you have your Ops Manager username and Public API Key.

    If you do not have your Public API Key, you need to generate a new Public API Key.

  2. Invoke the following Kubernetes command to create your secret:

    kubectl -n <metadata.namespace> create secret generic \
      <myCredentials> --from-literal="user=<first.last@example.com>" \
      --from-literal="publicApiKey=<my-public-api-key>"
    

    Note

    The -n flag limits the namespace to which this secret applies. All MongoDB Kubernetes resources must be in the same namespace with the secrets and ConfigMaps. The Kubernetes Operator does not use either the secrets or ConfigMaps.

  3. Invoke the following Kubernetes command to verify your secret:

    kubectl describe secrets/<myCredentials> -n <metadata.namespace>
    

    This command returns a secret description in the shell:

    Name:         <myCredentials>
    Namespace:    <metadata.namespace>
    Labels:       <none>
    Annotations:  <none>
    
    Type:  Opaque
    
    Data
    ====
    publicApiKey:  31 bytes
    user:          22 bytes