Skip to content

Commit df03dcf

Browse files
committed
2 parents fbf6a24 + f78c10c commit df03dcf

File tree

7 files changed

+206
-0
lines changed

7 files changed

+206
-0
lines changed

openshift/README.md

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
## Install and Configure Java
2+
3+
> Note: this is an optional step, you can use any Java version starting from 11 and above
4+
5+
Install Java 17 on your local machine:
6+
```
7+
❯ tar xvf OpenJDK17U-jdk_x64_linux_hotspot_17.0.2_8.tar.gz
8+
9+
❯ sudo mv jdk-17.0.2+8 /opt/java/
10+
```
11+
12+
Add Java to the profile:
13+
```
14+
❯ nano .profile
15+
```
16+
17+
Modify the file:
18+
```
19+
# adding java to the path
20+
PATH=$PATH:/opt/java/jdk-17.0.2+8/bin:/opt/java/jdk-17.0.2+8/lib
21+
JAVA_HOME=/opt/java/jdk-17.0.2+8
22+
```
23+
24+
Reload the profile and check java version
25+
```
26+
❯ source .profile
27+
❯ java -version
28+
```
29+
30+
Configure the VSCode (add to your settings.json):
31+
32+
```
33+
"java.configuration.runtimes": [
34+
{
35+
"name": "JavaSE-17",
36+
"path": "/opt/java/jdk-17.0.2+8",
37+
"default": true
38+
},
39+
]
40+
```
41+
42+
## Install Redis Operator and Create Redis Cluster
43+
44+
> Note: you should already have your OpenShift cluster installed and configured at this point. Check [RedHat documentation](https://docs.openshift.com/container-platform/4.9/installing/index.html) for details.
45+
46+
> Note: you also need to have OpenShift CLI installed on your local machine. Check [RedHat documentation](https://docs.openshift.com/container-platform/4.9/cli_reference/openshift_cli/getting-started-cli.html) on how to get it installed.
47+
48+
Export KUBECONFIG to point to your OpenShift cluster config:
49+
```
50+
export KUBECONFIG=/<your-cluster-configuration-dir>/auth/kubeconfig
51+
```
52+
53+
Create the new project (namespace) for Redis cluster:
54+
```
55+
oc new-project redis-ent-dev
56+
```
57+
Follow [this documentation](https://github.com/RedisLabs/redis-enterprise-k8s-docs/tree/master/openshift/OLM) to find and install _Redis Enterprise Operator_ in the OperatorHub - make sure to install it to the project you created in the prior step:
58+
![](images/install_operator.png)
59+
60+
> Note: this guide was created to simplify the deployment of RedisBank application in OpenShift environment. For production workloads you almost always want to deploy your workloads separately (to a different namespace) from Redis Enterprise namespace.
61+
62+
## Create Redis Database
63+
64+
First, create a secret for a default user in your database:
65+
66+
```
67+
oc apply -f bankdb-pwd.yaml
68+
```
69+
70+
> Note: if you want to modify the password, make sure you also change it in the `openshift` configuration for the application (application-openshift.properties).
71+
72+
To create a new database you can use the [provided resource file](bankdb.yaml):
73+
74+
> Note: modify the name and namespace for your database accordingly
75+
76+
> Note: the list of modules that the cluster supports can be found at the very bottom of your REC cluster YAML file:
77+
78+
![](images/modules_versions.png)
79+
80+
```
81+
oc apply -f bankdb.yaml
82+
```
83+
84+
## Build and Deploy the Application
85+
86+
We are going to use [Eclipse JKube Maven Plugin](https://www.eclipse.org/jkube/docs/openshift-maven-plugin#_configuration) for Kubernetes and OpenShift to automate the resources creation and also implement S2I (source to image) build process that is often used in OpenShift environment.
87+
88+
### Configure
89+
90+
In `pom.xml` add [jkube](https://github.com/eclipse/jkube/tree/master/openshift-maven-plugin) maven plugin - it will help to generate the required resources and deploy the application to OpenShift:
91+
92+
```
93+
<plugin>
94+
<groupId>org.eclipse.jkube</groupId>
95+
<artifactId>openshift-maven-plugin</artifactId>
96+
<version>1.7.0</version>
97+
</plugin>
98+
```
99+
100+
In `src/main/resources/application-openshift.properties` change the following settings:
101+
102+
```
103+
# stomp.host=<app-name-namespace>.apps.<cluster-name>.<dns-zone>
104+
# for example:
105+
stomp.host=redisbank-redis-ent-dev.apps.c1.openshift.demo.redislabs.com
106+
stomp.protocol=ws
107+
stomp.port=80
108+
spring.redis.host=bankdb
109+
spring.redis.port=12869
110+
spring.redis.password=redisbank
111+
```
112+
113+
> Note: make sure your application is using the `openshift` profile. One way to set this in a Spring application is to modify the `application.properties` file:
114+
115+
```
116+
spring.profiles.active=openshift
117+
```
118+
119+
### Build Locally
120+
121+
This will create and repackage the jar file with all the required resources:
122+
123+
```
124+
./mvnw clean package -Dmaven.test.skip=true
125+
```
126+
127+
### Build Remotely
128+
129+
This command will trigger the remote S2I build process. It will also create the _ImageSet_ and the _BuildConfig_ in your OpenShift cluster if not created yet:
130+
131+
```
132+
./mvnw oc:build -Dmaven.test.skip=true
133+
```
134+
135+
### Deploy
136+
137+
Generate the _DeploymentConfig_ resources for your application:
138+
```
139+
./mvnw oc:resource
140+
```
141+
142+
Apply the resources to create the _DeploymentConfig_, _Service_ and _Route_ generated in a previous step:
143+
144+
```
145+
./mvnw oc:apply
146+
```
147+
148+
> Note: you can use the undeploy command: `./mvnw oc:undeploy` if you need to undepoy the application completely
149+
150+
At this point of time your application is already deployed and supposed to be up and running. Go check the your Openshift web console on the status and pull the route url to access the app from your browser. This will typically look like this:
151+
152+
`http://redisbank-<namespace>.<cluster-name>.<dns-zone>`

openshift/bankdb-pwd.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
kind: Secret
2+
apiVersion: v1
3+
metadata:
4+
name: bankdb-pwd
5+
data:
6+
password: cmVkaXNiYW5r
7+
type: Opaque

openshift/bankdb.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
apiVersion: app.redislabs.com/v1alpha1
2+
kind: RedisEnterpriseDatabase
3+
metadata:
4+
name: bankdb
5+
namespace: redis-ent-dev
6+
spec:
7+
modulesList:
8+
- name: search
9+
version: 2.2.6
10+
- name: timeseries
11+
version: 1.4.13
12+
redisEnterpriseCluster:
13+
name: rec
14+
shardCount: 2
15+
shardsPlacement: dense
16+
databasePort: 12869
17+
databaseSecretName: bankdb-pwd
18+
memorySize: 1GB
75.6 KB
Loading
53.7 KB
Loading
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Properties for running inside OpenShift cluster:
2+
# ===============================================
3+
# stomp.host=<app-name>-<namespace>.apps.<cluster-name>.<dns-zone>
4+
# for example, if you have the following properties:
5+
# app-name = redisbank
6+
# namespace = redis-ent-dev
7+
# cluster-name = c1
8+
# dns-zone = openshift.demo.redislabs.com
9+
# then your host will be the following:
10+
# stomp.host=redisbank-redis-ent-dev.apps.c1.openshift.demo.redislabs.com
11+
stomp.host=redisbank-redis-ent-dev.apps.c1.openshift.demo.redislabs.com
12+
# ws | wss for websockets OR websockets secured accordingly
13+
stomp.protocol=ws
14+
# the default route will be 80 for http and 443 for https
15+
stomp.port=80
16+
# the service name of your database, get it using the command below:
17+
# oc get secret redb-bankdb -o jsonpath="{.data.service_names}" | base64 --decode
18+
spring.redis.host=bankdb
19+
# the port of your database, get it using the command below:
20+
# oc get secret redb-bankdb -o jsonpath="{.data.port}" | base64 --decode
21+
spring.redis.port=12869
22+
# password for the default user to your database, get it using the command below:
23+
# oc get secret redb-bankdb -o jsonpath="{.data.password}" | base64 --decode
24+
# OR if you created a custom secret for a database, then pull it from there, e.g.:
25+
# oc get secret bankdb-pwd -o jsonpath="{.data.password}" | base64 --decode
26+
spring.redis.password=redisbank

src/main/resources/application.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Profile
2+
# spring.profiles.active=openshift
3+
14
# Properties for running on localhost
25
stomp.host=localhost
36
stomp.protocol=ws

0 commit comments

Comments
 (0)