Page
Run and test inside OpenShift Dev Spaces and deploy it to OpenShift
The finish is in sight. Now that you have successfully created a Camel route file, it's time to run and test it inside OpenShift Dev Spaces then deploy in OpenShift.
What you need
- A workspace in Red Hat OpenShift Dev Spaces
- A no-cost Developer Sandbox for Red Hat OpenShift environment
What you will learn
- How to install launch Quarkus using Karavan
- How to deploy to Red Hat OpenShift
- How to inspect the OpenShift web console
Run and test inside OpenShift Dev Spaces
- Launch Camel as Quarkus using Karavan: JBang run (Figure 29).
- When prompted, enter
3
to trust the content from https://github.com/apache (Figure 30). - After the program compiles, it will wait at the following step and listen to port localhost:8080 (Figure 31).
- Leave the program running in the current terminal (Figure 32). Open a new terminal and switch to it to test the endpoint using the following cURL command:
curl localhost:8080 -X POST -d "{\"hello\":\"world\"}" -H "Content-Type: application/json"
- Switch back to the terminal running the program and verify the service printout for the body (Figure 33).
- Stop the running process by entering Ctrl + C or Command + C (Figure 34).
You have successfully developed a simple REST API using Camel and Quarkus. Now let's deploy to OpenShift as a Knative serverless service.
Deploy to OpenShift
- Update the
quarkus.kubernetes.deployment-target
toknative
(Figure 35). - Copy the login command from the OpenShift console (Figure 36).
- Make sure you log into OpenShift inside the Dev Spaces terminal and are in the correct project/namespace. Note your project name will be different from mine (Figure 37).
- Right-click on the project workspace area and choose Karavan: Deploy (Figure 38).
- Wait for the container image build to finish (Figure 39).
- A new build type source is automatically created for you (Figure 40).
Congratulations! You successfully created a Source-to-Image build and built container images. The image is now deployed as a Knative service (Red Hat OpenShift Serverless).
Inspect the OpenShift web console
- If you inspect the OpenShift web console, you'll notice a new Knative service deployed in Topology view. Wait for a while. Notice the pod has scaled to zero when the circle turns from blue to white (Figure 41).
- From the Topology view, click on the icon to get the serverless URL from the Knative service (Figure 42).
- Another way to get the URL is to use the
kn
CLI. Install thekn
CLI using the following command:mkdir -p /projects/.knative/bin wget -qO /projects/.knative/bin/kn https://github.com/knative/client/releases/download/knative-v1.11.0/kn-linux-amd64 chmod +x /projects/.knative/bin/kn echo "export PATH=\"/projects/.knative/bin:\$PATH\"" >> ~/.bashrc source ~/.bashrc
- List the serverless endpoint using the cURL command:
kn service list
- Test the serverless endpoint using the cURL command. The serverless spins up a new pod immediately to serve new requests (Figures 43 and 44):
MYURL=$(kn service list -o json | jq -r .items[0].status.url) curl -k $MYURL -X POST -d "{\"hello\":\"world\"}" -H "Content-Type: application/json"
- After a while, the pod will terminate itself and return all the memory and CPU resources back to the server.
Congratulations! You have successfully deployed a serverless service using Quarkus and Camel.
Conclusion
Creating a Camel integration and deploying it as a serverless service opens up a new approach to implementing Enterprise Integration Patterns (EIP) and helps systems connect to one another. Many exciting things are happening in the integration world. The Red Hat build of Apache Camel is a great place to learn more.