|
| 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 | + |
| 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 | + |
| 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>` |
0 commit comments