Skip to content
logo
Percona Operator for MongoDB
Generic Kubernetes installation
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
      • 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)

    Install Percona server for MongoDB on Kubernetes¶

    1. Clone the percona-server-mongodb-operator repository:

      $ git clone -b v1.14.0 https://github.com/percona/percona-server-mongodb-operator
      $ cd percona-server-mongodb-operator
      

      Note

      It is crucial to specify the right branch with -b option while cloning the code on this step. Please be careful.

    2. The Custom Resource Definition for Percona Server for MongoDB should be created from the deploy/crd.yaml file. The Custom Resource Definition extends the standard set of resources which Kubernetes “knows” about with the new items, in our case these items are the core of the operator. Apply it as follows:

      $ kubectl apply --server-side -f deploy/crd.yaml
      

      This step should be done only once; the step does not need to be repeated with any other Operator deployments.

    3. Create a namespace and set the context for the namespace. The resource names must be unique within the namespace and provide a way to divide cluster resources between users spread across multiple projects.

      So, create the namespace and save it in the namespace context for subsequent commands as follows (replace the <namespace name> placeholder with some descriptive name):

      $ kubectl create namespace <namespace name>
      $ kubectl config set-context $(kubectl config current-context) --namespace=<namespace name>
      

      At success, you will see the message that namespace/<namespace name> was created, and the context was modified.

    4. The role-based access control (RBAC) for Percona Server for MongoDB is configured with the deploy/rbac.yaml file. Role-based access is based on defined roles and the available actions which correspond to each role. The role and actions are defined for Kubernetes resources in the yaml file. Further details about users and roles can be found in Kubernetes documentation.

      $ kubectl apply -f deploy/rbac.yaml
      

      Note

      Setting RBAC requires your user to have cluster-admin role privileges. For example, those using Google Kubernetes Engine can grant user needed privileges with the following command:

      $ kubectl create clusterrolebinding cluster-admin-binding --clusterrole=cluster-admin --user=$(gcloud config get-value core/account)
      
    5. Start the operator within Kubernetes:

      $ kubectl apply -f deploy/operator.yaml
      
    6. Add the MongoDB Users secrets to Kubernetes. These secrets should be placed as plain text in the stringData section of the deploy/secrets.yaml file as login name and passwords for the user accounts (see Kubernetes documentation for details).

      After editing the yaml file, MongoDB Users secrets should be created using the following command:

      $ kubectl create -f deploy/secrets.yaml
      

      More details about secrets can be found in Users.

    7. Now certificates should be generated. By default, the Operator generates certificates automatically, and no actions are required at this step. Still, you can generate and apply your own certificates as secrets according to the TLS instructions.

    8. After the operator is started, Percona Server for MongoDB cluster can be created with the following command:

      $ kubectl apply -f deploy/cr.yaml
      

      The creation process may take some time. The process is over when all Pods have reached their Running status. You can check it with the following command:

      $ kubectl get pods
      

      The result should look as follows:

      NAME                                               READY   STATUS    RESTARTS   AGE
      my-cluster-name-cfg-0                              2/2     Running   0          11m
      my-cluster-name-cfg-1                              2/2     Running   1          10m
      my-cluster-name-cfg-2                              2/2     Running   1          9m
      my-cluster-name-mongos-0                           1/1     Running   0          11m
      my-cluster-name-mongos-1                           1/1     Running   0          11m
      my-cluster-name-mongos-2                           1/1     Running   0          11m
      my-cluster-name-rs0-0                              2/2     Running   0          11m
      my-cluster-name-rs0-1                              2/2     Running   0          10m
      my-cluster-name-rs0-2                              2/2     Running   0          9m
      percona-server-mongodb-operator-665cd69f9b-xg5dl   1/1     Running   0          37m
      
    9. Check connectivity to a newly created cluster.

      First of all, run a container with a MongoDB client and connect its console output to your terminal. The following command will do this, naming the new Pod percona-client:

      $ kubectl run -i --rm --tty percona-client --image=percona/percona-server-mongodb:4.4.18-18 --restart=Never -- bash -il
      

      Executing it may require some time to deploy the correspondent Pod. Now run mongo tool in the percona-client command shell using the login (which is userAdmin) with a proper password obtained from the Secret, and a proper namespace name instead of the <namespace name> placeholder:

      percona-client:/$ mongo "mongodb://userAdmin:userAdmin123456@my-cluster-name-mongos.<namespace name>.svc.cluster.local/admin?ssl=false"
      

    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.