README
¶
percona-server-mongodb-operator
A Kubernetes operator for Percona Server for MongoDB based on the Operator SDK.
Table of Contents
- DISCLAIMER
- Requirements
- Run the Operator
- Connect to the MongoDB Replica Set
- Required Secrets
- Configuration
DISCLAIMER
This code is incomplete, expect major issues and changes until this repo has stabilised!
Requirements
The operator was developed/tested for:
- Percona Server for MongoDB 3.6 or greater with:
- Authentication enabled
- Replication enabled
- Kubernetes version 1.10 to 1.11 or OpenShift 3.9 to 3.11
- Go 1.11
Run the Operator
-
Add the 'psmdb' Namespace
on Kubernetes:
kubectl create namespace psmdb kubectl config set-context $(kubectl config current-context) --namespace=psmdbon OpenShift:
oc new-project psmdb -
Add the MongoDB Users secrets to Kubernetes. Update mongodb-users.yaml with new passwords!
on Kubernetes:
kubectl create -f deploy/mongodb-users.yamlon OpenShift:
oc create -f deploy/mongodb-users.yaml -
Extra step for Google Kubernetes Engine
kubectl create clusterrolebinding cluster-admin-binding1 --clusterrole=cluster-admin --user=<myname@example.org> -
Create RBAC and CustomResourceDefinition
This step require that your user needs to have cluster-admin role privileges.
Detailed about users and roles:
Kubernetes: documentation
OpenShift: documentation
on Kubernetes:
kubectl create -f deploy/crd.yaml kubectl create -f deploy/rbac.yamlon OpenShift:
oc project mykola-psmdb oc create -f deploy/crd.yaml oc create -f deploy/rbac.yaml -
Extra step for OpenShift, if you want to manage PSMDB cluster from non-privilegied user, you can grant permissions by applying next clusterrole
oc create clusterrole psmdb-admin --verb="*" --resource=perconaservermongodbs.psmdb.percona.com oc adm policy add-cluster-role-to-user psmdb-admin <some-user> -
Start the percona-server-mongodb-operator within Kubernetes:
kubectl create -f deploy/operator.yaml -
Create the Percona Server for MongoDB cluster:
on Kubernetes:
kubectl apply -f deploy/cr.yamlon OpenShift:
- Uncomment the deploy/cr.yaml field '#platform:' and set it to 'platform: openshift'. Example:
apiVersion: psmdb.percona.com/v1alpha1 kind: PerconaServerMongoDB metadata: name: my-cluster-name spec: platform: openshift ... ...- Create/apply the CR:
oc apply -f deploy/cr.yaml -
Wait for the operator and replica set pod reach Running state:
$ kubectl get pods NAME READY STATUS RESTARTS AGE my-cluster-name-rs0-0 1/1 Running 0 8m my-cluster-name-rs0-1 1/1 Running 0 8m my-cluster-name-rs0-2 1/1 Running 0 7m percona-server-mongodb-operator-754846f95d-sf6h6 1/1 Running 0 9m
Connect to the MongoDB Replica Set
- From a 'mongo' shell add a readWrite user for use with an application (hostname/replicaSet in mongo uri may vary for your situation):
$ kubectl run -i --rm --tty percona-client --image=percona/percona-server-mongodb:3.6 --restart=Never -- bash -il mongodb@percona-client:/$ mongo "mongodb+srv://userAdmin:userAdmin123456@my-cluster-name-rs0.psmdb.svc.cluster.local/admin?replicaSet=rs0&ssl=false" rs0:PRIMARY> db.createUser({ user: "myApp", pwd: "myAppPassword", roles: [ { db: "myApp", role: "readWrite" } ] }) Successfully added user: { "user" : "myApp", "roles" : [ { "db" : "myApp", "role" : "readWrite" } ] } - Again from a 'mongo' shell, insert and retrieve a test document in the 'myApp' database as the new application user:
$ kubectl run -i --rm --tty percona-client --image=percona/percona-server-mongodb:3.6 --restart=Never -- bash -il mongodb@percona-client:/$ mongo "mongodb+srv://myApp:myAppPassword@my-cluster-name-rs0.psmdb.svc.cluster.local/admin?replicaSet=rs0&ssl=false" rs0:PRIMARY> use myApp switched to db myApp rs0:PRIMARY> db.test.insert({ x: 1 }) WriteResult({ "nInserted" : 1 }) rs0:PRIMARY> db.test.findOne() { "_id" : ObjectId("5bc74ef05c0ec73be760fcf9"), "x" : 1 }
Static Endpoints List
If you prefer to use a static server list (instead of using mongodb+srv:// to detect servers) use 'kubectl describe service' to gather the list of endpoints.
Example (see 'Endpoints:' below):
$ kubectl describe service my-cluster-name-rs0 | grep 'Endpoints:' Endpoints: 172.17.0.10:27017,172.17.0.12:27017,172.17.0.9:27017
Required Secrets
The operator requires Kubernetes Secrets to be deployed before it is started.
The name of the required secrets can be set in deploy/cr.yaml under the section spec.secrets.
MongoDB System Users
Default Secret name: my-cluster-name-mongodb-users Secret name field: spec.secrets.users
The operator requires system-level MongoDB Users to automate the MongoDB deployment. These users should not be used to run an application!
| User Purpose | Username Secret Key | Password Secret Key | MongoDB Role |
|---|---|---|---|
| Backup/Restore | MONGODB_BACKUP_USER | MONGODB_BACKUP_PASSWORD | backup, clusterMonitor, restore |
| Cluster Admin | MONGODB_CLUSTER_ADMIN_USER | MONGODB_CLUSTER_ADMIN_PASSWORD | clusterAdmin |
| Cluster Monitor | MONGODB_CLUSTER_MONITOR_USER | MONGODB_CLUSTER_MONITOR_PASSWORD | clusterMonitor |
| User Admin | MONGODB_USER_ADMIN_USER | MONGODB_USER_ADMIN_PASSWORD | userAdmin |
Development Mode
Note: Do not use the default MongoDB Users in Production!
To make development/testing easier a secrets file with default MongoDB System User/Passwords is located at 'deploy/mongodb-users.yaml'.
The development-mode credentials from deploy/mongodb-users.yaml are:
| Secret Key | Secret Value |
|---|---|
| MONGODB_BACKUP_USER | backup |
| MONGODB_BACKUP_PASSWORD | backup123456 |
| MONGODB_CLUSTER_ADMIN_USER | clusterAdmin |
| MONGODB_CLUSTER_ADMIN_PASSWORD | clusterAdmin123456 |
| MONGODB_CLUSTER_MONITOR_USER | clusterMonitor |
| MONGODB_CLUSTER_MONITOR_PASSWORD | clusterMonitor123456 |
| MONGODB_USER_ADMIN_USER | userAdmin |
| MONGODB_USER_ADMIN_PASSWORD | userAdmin123456 |
MongoDB Internal Authentication Key (optional)
Default Secret name: my-cluster-name-mongodb-key Secret name field: spec.secrets.key
By default, the operator will create a random, 1024-byte key for MongoDB Internal Authentication if it does not already exist.
If you would like to deploy a different key, create the secret manually before starting the operator.
Configuration
The operator is configured via the spec section of the deploy/cr.yaml file.
Spec
YAML Path: spec
| Key | Value Type | Default | Description |
|---|---|---|---|
| platform | string | kubernetes | Override/set the Kubernetes platform: kubernetes or openshift. Set openshift on OpenShift 3.11+ |
| version | string | 3.6 | The Dockerhub tag of percona/percona-server-mongodb to deploy |
| secrets | subdoc | Operator secrets section | |
| replsets | array | Operator MongoDB Replica Set section | |
| mongod | subdoc | Operator MongoDB Mongod configuration section |
Secrets
YAML Path: spec.secrets
| Key | Value Type | Default | Description |
|---|---|---|---|
| key | string | my-cluster-name-mongodb-key | The secret name for the MongoDB Internal Auth Key. This secret is auto-created by the operator if it doesn't exist |
| users | string | my-cluster-name-mongodb-users | The secret name for the MongoDB users required to run the operator. This secret is required to run the operator! |
Replsets
YAML Path: spec.replsets
| Key | Value Type | Default | Description |
|---|---|---|---|
| name | string | rs0 | The name of the MongoDB Replica Set |
| size | int | 3 | The size of the MongoDB Replica Set, must be >= 3 for High-Availability |
| storageClass | string | Set the Kubernetes Storage Class to use with the MongoDB Persistent Volume Claim | |
| resources.limits.cpu | string | Kubernetes CPU limit for MongoDB container | |
| resources.limits.memory | string | Kubernetes Memory limit for MongoDB container | |
| resources.limits.storage | string | Kubernetes Storage limit for Persistent Volume Claim | |
| resources.requests.cpu | string | Kubernetes CPU requests for MongoDB container | |
| resources.requests.memory | string | Kubernetes Memory requests for MongoDB container |
Mongod
YAML Path: spec.mongod
| Key | Value Type | Default | Description |
|---|---|---|---|
| net.port | int | 27017 | Sets the MongoDB 'net.port' option |
| net.hostPort | int | 0 | Sets the Kubernetes 'hostPort' option |
| security.redactClientLogData | bool | false | Enables/disables PSMDB Log Redaction |
| setParameter.ttlMonitorSleepSecs | int | 60 | Sets the PSMDB 'ttlMonitorSleepSecs' option |
| setParameter.wiredTigerConcurrentReadTransactions | int | 128 | Sets the 'wiredTigerConcurrentReadTransactions' option |
| setParameter.wiredTigerConcurrentWriteTransactions | int | 128 | Sets the 'wiredTigerConcurrentWriteTransactions' option |
| storage.engine | string | wiredTiger | Sets the 'storage.engine' option |
| storage.inMemory.inMemorySizeRatio | float | 0.9 | Ratio used to compute the 'storage.engine.inMemory.inMemorySizeGb' option |
| storage.mmapv1.nsSize | int | 16 | Sets the 'storage.mmapv1.nsSize' option |
| storage.mmapv1.smallfiles | bool | false | Sets the 'storage.mmapv1.smallfiles' option |
| storage.wiredTiger.engineConfig.cacheSizeRatio | float | 0.5 | Ratio used to compute the 'storage.wiredTiger.engineConfig.cacheSizeGB' option |
| storage.wiredTiger.engineConfig.directoryForIndexes | bool | false | Sets the 'storage.wiredTiger.engineConfig.directoryForIndexes' option |
| storage.wiredTiger.engineConfig.journalCompressor | string | snappy | Sets the 'storage.wiredTiger.engineConfig.journalCompressor' option |
| storage.wiredTiger.collectionConfig.blockCompressor | string | snappy | Sets the 'storage.wiredTiger.collectionConfig.blockCompressor' option |
| storage.wiredTiger.indexConfig.prefixCompression | bool | true | Sets the 'storage.wiredTiger.indexConfig.prefixCompression' option |
| operationProfiling.mode | string | slowOp | Sets the 'operationProfiling.mode' option |
| operationProfiling.slowOpThresholdMs | int | 100 | Sets the 'operationProfiling.slowOpThresholdMs' option |
| operationProfiling.rateLimit | int | 1 | Sets the 'operationProfiling.rateLimit' option |
| auditLog.destination | string | Sets the 'auditLog.destination' option | |
| auditLog.format | string | BSON | Sets the 'auditLog.format' option |
| auditLog.filter | string | {} | Sets the 'auditLog.filter' option |
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
percona-server-mongodb-operator
command
|
|
|
internal
|
|
|
sdk/mocks
Code generated by mockery v1.0.0.
|
Code generated by mockery v1.0.0. |
|
pkg
|
|
|
apis/psmdb/v1alpha1
+k8s:deepcopy-gen=package +groupName=psmdb.percona.com
|
+k8s:deepcopy-gen=package +groupName=psmdb.percona.com |