Skip to content

Commit

Permalink
Consolidate apiHost & host for RabbitMQ scaler
Browse files Browse the repository at this point in the history
Signed-off-by: Tomek Urbaszek <tomasz.urbaszek@polidea.com>
  • Loading branch information
turbaszek committed Sep 10, 2020
1 parent 4671c03 commit 3f03e0a
Show file tree
Hide file tree
Showing 3 changed files with 242 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
public/
resources/_gen/
# GoLand local configuration
.idea/
121 changes: 121 additions & 0 deletions content/docs/1.5/scalers/rabbitmq-queue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
+++
title = "RabbitMQ Queue"
layout = "scaler"
availability = "v1.0+"
maintainer = "Microsoft"
description = "Scale applications based on RabbitMQ Queue."
go_file = "rabbitmq_scaler"
+++

### Trigger Specification

This specification describes the `rabbitmq` trigger for RabbitMQ Queue.

```yaml
triggers:
- type: rabbitmq
metadata:
host: RabbitMqHost # Optional. If not specified, it must be done by using TriggerAuthentication.
protocol: amqp # Optional. Specifies protocol to use. Either amqp or http
queueLength: '20' # Optional. Queue length target for HPA. Default: 20 messages
queueName: testqueue
authenticationRef:
name: keda-trigger-auth-rabbitmq-conn
```
**Parameter list:**
- `host`: Value is the name of the environment variable your deployment uses to get the connection string.
This is usually resolved from a `Secret V1` or a `ConfigMap V1` collections. `env` and `envFrom` are both
supported. The resolved host should either follow a format like `amqp://guest:password@localhost:5672/vhost` or
`https://guest:password@localhost:443/vhostname`.
- `queueName`: Name of the queue to read message from. Required.
- `queueLength`: Queue length target for HPA. Default is 20. Optional.
- `protocol`: Protocol to be used for communication. Either `http` or `amqp`. It should correspond with the `host` value.


### Authentication Parameters

TriggerAuthentication CRD is used to connect and authenticate to RabbitMQ:

- `host`: AMQP URI connection string if `protocol=amqp`, like `amqp://guest:password@localhost:5672/vhost` or
`https://guest:password@localhost:443/vhostname` if `protocol=http`.

### Example

AMQP protocol:

```yaml
apiVersion: v1
kind: Secret
metadata:
name: keda-rabbitmq-secret
data:
host: <AMQP URI connection string> # base64 encoded value of format amqp://guest:password@localhost:5672/vhost
---
apiVersion: keda.k8s.io/v1alpha1
kind: TriggerAuthentication
metadata:
name: keda-trigger-auth-rabbitmq-conn
namespace: default
spec:
secretTargetRef:
- parameter: host
name: keda-rabbitmq-secret
key: host
---
apiVersion: keda.k8s.io/v1alpha1
kind: ScaledObject
metadata:
name: rabbitmq-scaledobject
namespace: default
spec:
scaleTargetRef:
deploymentName: rabbitmq-deployment
triggers:
- type: rabbitmq
metadata:
queueName: testqueue
queueLength: "20"
authenticationRef:
name: keda-trigger-auth-rabbitmq-conn
```

HTTP protocol:

```yaml
apiVersion: v1
kind: Secret
metadata:
name: keda-rabbitmq-secret
data:
host: <HTTP API endpoint> # base64 encoded value of format https://guest:password@localhost:443/vhostname
---
apiVersion: keda.k8s.io/v1alpha1
kind: TriggerAuthentication
metadata:
name: keda-trigger-auth-rabbitmq-conn
namespace: default
spec:
secretTargetRef:
- parameter: host
name: keda-rabbitmq-secret
key: host
---
apiVersion: keda.k8s.io/v1alpha1
kind: ScaledObject
metadata:
name: rabbitmq-scaledobject
namespace: default
spec:
scaleTargetRef:
deploymentName: rabbitmq-deployment
triggers:
- type: rabbitmq
metadata:
protocol: http
queueName: testqueue
queueLength: "20"
authenticationRef:
name: rabbitmq-consumer-trigger
```
119 changes: 119 additions & 0 deletions content/docs/2.0/migration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
+++
title = "Migration Guide"
+++

## Migrating from KEDA v1 to v2

Please note that you **can not** run both KEDA v1 and v2 on the same Kubernetes cluster. You need to [uninstall](../../1.5/deploy) KEDA v1 first, in order to [install](../deploy) and use KEDA v2.

KEDA v2 is using a new API namespace for it's Custom Resources Definitions (CRD): `keda.sh` instead of `keda.k8s.io` and introduces a new Custom Resource for scaling of Jobs. See full details on KEDA Custom Resources [here](../concepts/#custom-resources-crd).

### Scaling of Deployments
In order to scale `Deployments` with KEDA v2, you need to do only a few modifications to existing v1 `ScaledObjects` definitions, so they comply with v2:
- Change the value of `apiVersion` property from `keda.k8s.io/v1alpha1` to `keda.sh/v1alpha1`
- Rename property `spec.scaleTargetRef.deploymentName` to `spec.scaleTargetRef.name`
- Label `deploymentName` (in `metadata.labels.`) is no longer needed to be specified on v2 ScaledObject (it was mandatory on older versions of v1)

Please see the examples below or refer to the full [v2 ScaledObject Specification](../concepts/scaling-deployments/#scaledobject-spec)

**Example of v1 ScaledObject**
```yaml
apiVersion: keda.k8s.io/v1alpha1
kind: ScaledObject
metadata:
name: {scaled-object-name}
labels:
deploymentName: {deployment-name}
spec:
scaleTargetRef:
deploymentName: {deployment-name}
containerName: {container-name}
pollingInterval: 30
cooldownPeriod: 300
minReplicaCount: 0
maxReplicaCount: 100
triggers:
# {list of triggers to activate the deployment}
```

**Example of v2 ScaledObject**
```yaml
apiVersion: keda.sh/v1alpha1 # <--- Property value was changed
kind: ScaledObject
metadata: # <--- labels.deploymentName is not needed
name: {scaled-object-name}
spec:
scaleTargetRef:
name: {deployment-name} # <--- Property name was changed
containerName: {container-name}
pollingInterval: 30
cooldownPeriod: 300
minReplicaCount: 0
maxReplicaCount: 100
triggers:
# {list of triggers to activate the deployment}
```


### Scaling of Jobs

TODO description

Please see the examples below or refer to the full [v2 ScaledJob Specification](../concepts/scaling-jobs/#scaledjob-spec)

**Example of v1 ScaledObject for Jobs scaling**
```yaml
apiVersion: keda.k8s.io/v1alpha1
kind: ScaledObject
metadata:
name: {scaled-object-name}
spec:
scaleType: job
jobTargetRef:
parallelism: 1
completions: 1
activeDeadlineSeconds: 600
backoffLimit: 6
template:
# {job template}
pollingInterval: 30
cooldownPeriod: 300
minReplicaCount: 0
maxReplicaCount: 100
triggers:
# {list of triggers to create jobs}
```

**Example of v2 ScaledJob**

TODO

### Changes in scalers

#### RabbitMQ scaler

In KEDA 2.0 the RabbitMQ scaler has only `host` parameter, and the protocol for communication can be specified by
`protocol` (http or amqp). The default value is `amqp`. The behavior changes only for scalers that were using HTTP
protocol.

Example of RabbitMQ trigger before 2.0:
```yaml
triggers:
- type: rabbitmq
metadata:
queueLength: '20'
queueName: testqueue
includeUnacked: 'true'
apiHost: 'https://guest:password@localhost:443/vhostname'
```
The same trigger in 2.0:
```yaml
triggers:
- type: rabbitmq
metadata:
queueLength: '20'
queueName: testqueue
protocol: 'http'
host: 'https://guest:password@localhost:443/vhostname'
```

0 comments on commit 3f03e0a

Please sign in to comment.