Skip to content

Commit

Permalink
add mongoDB.md
Browse files Browse the repository at this point in the history
  • Loading branch information
高强 committed Jan 9, 2021
1 parent 07286db commit cf960f3
Showing 1 changed file with 110 additions and 0 deletions.
110 changes: 110 additions & 0 deletions content/docs/2.1/scalers/mongo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
+++
title = "mongoDB"
layout = "scaler"
maintainer = "Community"
description = "Scale applications based on mongoDB."
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"
```
**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 is used as targetAverageValue in HPA.

To provide information about how to connect to mongoDB you can provide
- `connectionStringFromEnv` - 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"
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==
```

0 comments on commit cf960f3

Please sign in to comment.