From cdceb3b7878cb849df9eb54fa6e7b3de8536f7ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AB=98=E5=BC=BA?= Date: Sat, 23 Jan 2021 12:57:55 +0800 Subject: [PATCH] add mongodb scaler doc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 高强 --- content/docs/2.1/scalers/mongodb.md | 116 ++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 content/docs/2.1/scalers/mongodb.md diff --git a/content/docs/2.1/scalers/mongodb.md b/content/docs/2.1/scalers/mongodb.md new file mode 100644 index 000000000..504afd83d --- /dev/null +++ b/content/docs/2.1/scalers/mongodb.md @@ -0,0 +1,116 @@ ++++ +title = "MongoDB" +layout = "scaler" +maintainer = "Community" +description = "Scale applications based on MongoDB queries." +availability = "v2.1+" +go_file = "mongodb_scaler" ++++ + +### Trigger Specification + +This specification describes the `mongodb` trigger that scales based on result of MongoDB query. + +```yaml +triggers: + - type: mongodb + metadata: + # Required: database name + dbName: "test" + # Required: collection name + collection: "test_collection" + # Required: query expr, used by filter data + query: '{"region":"eu-1","state":"running","plan":"planA"}' + # Required: according to the number of query result, to scale job + queryValue: "1" + # Optional: This value will be assign to the metric + metricName: "global-metric" +``` + +**Parameter list:** + +- `dbName` - Name of the database +- `collection` - Name of the collection +- `query` - A MongoDB query that should return single numeric value +- `queryValue` - A threshold that will define when scaling should occur +- `metricName` - An optional name to assign to the metric. + +To provide information about how to connect to MongoDB you can provide + +- `connectionStringFromEnv` - A MongoDB connection string that should point to environment variable with valid value + +Or provide more detailed information: + +- `host` - The host of the MongoDB server +- `port` - The port of the MongoDB server +- `username` - Username to authenticate with to MongoDB database +- `passwordFromEnv` - Password for the given user + +### Authentication Parameters + +You can authenticate by using connection string or password authentication. + +**Connection String Authentication:** + +- `connectionString` - Connection string for MongoDB database + +**Password Authentication:** + +- `password` - Password for the configured user to login to MongoDB database variables. + +### Example + +Here is an example of how to deploy a scaled Job with the `MongoDB` scale trigger which uses `TriggerAuthentication`. + +```yaml +apiVersion: keda.sh/v1alpha1 +kind: ScaledJob +metadata: + name: mongodb-job +spec: + jobTargetRef: + template: + spec: + containers: + - name: mongodb-update + image: 1314520999/mongodb-update:latest + args: + - --connectStr=mongodb://test_user:test_password@mongoDB-svc.mongoDB.svc.cluster.local:27017/test + - --dataBase=test + - --collection=test_collection + imagePullPolicy: IfNotPresent + restartPolicy: Never + backoffLimit: 1 + pollingInterval: 30 # Optional. Default: 30 seconds + maxReplicaCount: 30 # Optional. Default: 100 + successfulJobsHistoryLimit: 0 # Optional. Default: 100. How many completed jobs should be kept. + failedJobsHistoryLimit: 10 # Optional. Default: 100. How many failed jobs should be kept. + triggers: + - type: mongodb + metadata: + dbName: "test" + collection: "test_collection" + query: '{"region":"eu-1","state":"running","plan":"planA"}' + queryValue: "1" + metricName: "global-metric" + authenticationRef: + name: mongodb-trigger +--- +apiVersion: keda.sh/v1alpha1 +kind: TriggerAuthentication +metadata: + name: mongodb-trigger +spec: + secretTargetRef: + - parameter: connectionString + name: mongodb-secret + key: connect +--- +apiVersion: v1 +kind: Secret +metadata: + name: mongodb-secret +type: Opaque +data: + connect: bW9uZ29kYjovL3Rlc3RfdXNlcjp0ZXN0X3Bhc3N3b3JkQG1vbmdvZGItc3ZjLm1vbmdvREIuc3ZjLmNsdXN0ZXIubG9jYWw6MjcwMTcvdGVzdA== +```