Skip to content

Commit

Permalink
Merge pull request #728 from entando/ENDOC-683-v2
Browse files Browse the repository at this point in the history
Endoc 683-Redis v2
jyunmitch authored May 11, 2023
2 parents 0f7cb79 + 5d577a8 commit e2c3881
Showing 3 changed files with 99 additions and 65 deletions.
1 change: 1 addition & 0 deletions vuepress/docs/.vuepress/next.js
Original file line number Diff line number Diff line change
@@ -440,6 +440,7 @@ module.exports = {
path + 'consume/external-id-management.md',
path + 'consume/entando-operator.md',
path + 'consume/invoking-api.md',
path + 'consume/redis.md',
path + 'consume/mt-cds.md'
]
},
67 changes: 2 additions & 65 deletions vuepress/docs/next/tutorials/consume/high-avail-tutorial.md
Original file line number Diff line number Diff line change
@@ -15,6 +15,8 @@ To scale an Entando Application without the use of clustered storage assumes all
## Clustering
This section describes how to set up a clustered Entando App Engine in the `entando-de-app` image. The goal is to deploy a clustered instance of the App Engine and verify the scalable deployment and HA of the application.

To employ **Redis** for cache management, refer to the [Redis Integration tutorial](redis.md).

### Prerequisites
- An existing deployment of an Entando App or the ability to create one.
- If you haven't created a deployment or don't have a YAML file for an Entando deployment, follow the [Quickstart instructions](../../../docs/getting-started/).
@@ -71,68 +73,3 @@ Validating the shared cache can be done in a process similar to the clustered in
5. Fetch the recently created data and verify that the data are returned.


## Configuring and Deploying with Redis

In this section, an Entando App Engine instance is deployed using Redis as a cache for data served by the App Engine. For more information on the cache configuration for the App Engine, see [high availability in an Entando Application](../../docs/consume/high-avail-application.md).

### Deploy Redis to Kubernetes

1. Create the Redis deployment and expose the endpoints:

```sh
kubectl create deployment redis --image=redis:7
```
```sh
kubectl expose deployment redis --port=6379 --target-port=6379 -n YOUR-NAMESPACE
```
2. Install the Redis CLI for your environment per <https://redis.io/topics/rediscli>.
3. Get the IP for your Redis deployment:
```sh
kubectl get service -n YOUR-NAMESPACE
```
4. Validate your deployment:

```sh
redis-cli -h 10.43.99.198 -p 6379 ping
```
* Should respond PONG.


```sh
redis-cli -h 10.43.99.198 -p 6379 incr mycounter
```
* Should increment each time.


## Configure the Implementation

1. Download the `entando-app.yaml` template:

<EntandoCode>curl -sLO "https://raw.githubusercontent.com/entando/entando-releases/{{$site.themeConfig.entando.fixpack.v71}}/dist/ge-1-1-6/samples/entando-app.yaml"</EntandoCode>

2. Add these environment variables to the `EntandoApp` YAML to match your Redis instance. The variables to create are `REDIS_ACTIVE`, `REDIS_SESSION_ACTIVE`, `REDIS_ADDRESS` (e.g. _redis://localhost:6379_), and `REDIS_PASSWORD`.
```yaml
data:
environmentVariables:
- name: REDIS_ACTIVE
value: "true"
- name: REDIS_ADDRESS
value: YOUR-REDIS-URL
- name: REDIS_SESSION_ACTIVE
value: "true"
- name: REDIS_PASSWORD
valueFrom:
secretKeyRef:
key: password
name: YOUR-REDIS-SECRET-NAME
optional: false
```
Both REDIS_ACTIVE and REDIS_SESSION_ACTIVE need to be set to "true" to enable the storage of HTTP sessions. If only REDIS_ACTIVE is set to "true", Redis is used just for the cache.
>NOTE: This example uses a Secret for the `REDIS_PASSWORD`, which is recommended. You can also hardcode the password in the YAML for testing purposes, but the use of clear text passwords in deployment files is not recommended. **Create and use a Secret for the password as a best practice.**

3. Deploy your file
```sh
kubectl apply -f entando-app.yaml
```
You now have a high availability cluster of Entando with Redis implementation.
96 changes: 96 additions & 0 deletions vuepress/docs/next/tutorials/consume/redis.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
---
sidebarDepth: 2
---

# Redis Integration
Redis database server can be used on Entando for cache management in high availability applications. It is a requirement for Entando Applications serving multiple tenants. This tutorial describes the steps to integrate Redis for both high availability and multitenancy.

See [Entando Multitenancy](multitenancy-tutorial.md) for more information.

## Prerequisites
* [A working instance of Entando](../../../docs/getting-started/README.md) based on the default Tomcat server image

* Verify dependencies with the [Entando CLI](../../docs/getting-started/entando-cli.md#check-the-environment): `ent check-env develop`

* Helm 3 installed in your local environment

## Install [Redis Sentinel](https://github.com/entando-ps/redis-sentinel)
1. Clone the project
```
git clone https://github.com/entando-ps/redis-sentinel.git
```

> Notes:
> * The number of Redis replica is 3; it can be adjusted by modifying the `replica.replicaCount` in the `values.yaml` file.
> * By default, the Redis Sentinel configuration does not use a password. For an external Redis installation where a password is required, you can define a value for the parameter `global.redis.password` in `values.yaml` so that Helm creates a secret for it.
3. Set your Kubernetes context to the proper namespace:
```
kubectl config set-context --current --namespace=YOUR-NAMESPACE
```

4. Run the custom script:
```
./install.sh
```

## Modify the App Engine

1. Scale down the `entando-de-app` deployment to 0
``` bash
kubectl scale deploy/YOUR-APP-NAME-deployment --replicas=0 -n YOUR-NAMESPACE
```

3. Edit the `entando-de-app` deployment image and add the environment variables listed below. For
`REDIS_ADDRESSES`, note the Sentinel node's logs that lists the domain names of the Redis cluster instances. List the master first, then the replicas as shown in this example.

``` yaml
spec:
container:
- env:
- name: REDIS_ACTIVE
value: "true"
- name: REDIS_ADDRESSES
value: redis-node-0.redis-headless.YOUR-NAMESPACE.svc.cluster.local:26379,redis-node-1.redis-headless.YOUR-NAMESPACE.svc.cluster.local:26379,redis-node-2.redis-headless.YOUR-NAMESPACE.svc.cluster.local:26379
- name: REDIS_SESSION_ACTIVE
value: "true"
```
3. Scale the `entando-de-app` deployment back up to 1 or more replicas and check the system for any issues.
``` bash
kubectl scale deploy/YOUR-APP-NAME-deployment --replicas=1 -n YOUR-NAMESPACE
```

> Note:
>
> To check that your Redis is running as expected, shell into the `redis-node-0` pod, then execute `redis-cli`. Run `KEYS *` to list all current keys present in the cache.

## Additional Settings
1. Use a password for Redis
If a password was used in your Redis `values.yaml` file, an additional environment variable is required in the `entando-de-app` deployment image.

``` yaml
spec:
container:
- env:
- name: REDIS_PASSWORD
valueFrom:
secretKeyRef:
key: YOUR_REDIS_PASSWORD_KEY
name: YOUR-REDIS-SECRET-NAME
optional: false
```

2. Monitor Redis
When Redis Sentinel is active, Sentinel monitoring can be utilized to trigger an automatic failover process by using an additional environment variable in the `entando-de-app` deployment image.

```
spec:
container:
- env:
- name: REDIS_USE_SENTINEL_EVENTS
value: "true"
```
If this env variable is set to `true`, the Sentinel failover process for electing a new master will be used when a master node becomes unreachable.
When the variable is set to `false`, the application doesn't subscribe to the events but uses a scheduler to periodically check the master IP to detect if the master has changed. This can be useful as a fallback method in case of a problem with events detections.

0 comments on commit e2c3881

Please sign in to comment.