Quickstart
In this guide, we will be using odo to set up a todo application based on Java Spring Boot framework for the backend/APIs, ReactJS for the frontend, and PostgreSQL database to store the todo items.
We will be performing following tasks using odo in this guide:
- Create a project
- Create an odo component for both the frontend and backend applications
- Create an Operator backed service for PostgreSQL database
- Link the backend component with the PostgreSQL service
- Link the frontend component with the backend component
At the end of the guide, you will be able to list, add and delete todo items from the web browser.
#
Prerequisites- A development Kubernetes cluster with Operator Lifecycle Manager setup on it.
- This guide is written for minikube users, hence you will notice the usage of
minikube ip
command to get the IP address of the Kubernetes cluster. - If you are using a Kubernetes cluster other than minikube, you will need to check with cluster administrator for the cluster IP to be used with
--host
flag. - If you are using Code Ready Containers (CRC) or another form of OpenShift cluster, you can skip the part of
odo url create
because odo automatically creates URL for the component using OpenShift Routes.
- This guide is written for minikube users, hence you will notice the usage of
- Install the Crunchy Postgres Operator on the cluster. Assuming you have admin privileges on the development Kubernetes cluster, you can install it using below command:
- Have the odo binary installed on your system.
#
Create a projectWe will create a project named quickstart
on the cluster to keep quickstart related activities separate from rest of the cluster:
#
Clone the codeClone this git repository and cd
into it:
#
Create the backend componentFirst we create a component for the backend application which is a Java Spring Boot based REST API. It will help us list, insert and delete todos from the database. Execute below steps:
The minikube ip
command helps get the IP address of the minikube instance. It is required to create a URL accesible from the web browser of the host system on which minikube is running.
#
Create the Postgres databaseIn the prerequisites section, we installed Postgres Operator. Before being able to create a service using it, first ensure that the Operator is installed correctly. You should see the Postgres Operator like in below output. Note that you might see more Operators in the output if there are other Operators installed on your cluster:
If you don't see the Postgres Operator here, it might be still installing. Take a look at what you see in the PHASE
column in below output:
If the PHASE
is something other than Succeeded
, you won't see it in odo catalog list services
output, and you won't be able to create a working Operator backed service out of it either.
Now create the service using:
Example output:
The postgrescluster.yaml
file in the repository contains configuration that should help bring up a Postgres database. Do a push to create the database on the cluster:
#
Link the backend component and the databaseNext, we need to link the backend component with the database. Let's get the information about the database service first:
Example output:
Now, let's link the backend component with the above service using:
Now, get the URL (odo url list
) for the backend component, append api/v1/todos
to it and open it on your browser:
Example output:
In this case, the URL to load in browser would be http://8080-tcp.192.168.39.117.nip.io/api/v1/todos
. Note that the URL would be different in your case depending on what the minikube VM's IP is. When you load the URL in the browser, you should see an empty list:
#
Create the frontend componentOur frontend component is a React application that communicates with the backend component. Create the frontend component:
Open the URL for the component in the browser, but note that you won't be able to add, remove or list the todos yet because we haven't linked the frontend and the backend components:
#
Link the frontend and backend componentsTo link the frontend component to backend:
Now reload the URL of frontend component and try adding and removing some todo items. The list of items appears by default on the same page just below the input box that reads Add a new task
.