With the Open Liberty devfile stack, you can develop new and existing cloud-native applications directly in an OpenShift cluster. But what if you don’t have access to a remote cluster? No problem! You can still get all of the benefits of stack development locally with Minikube.
Check out a quick demo:
Minikube is a Kubernetes cluster that runs locally, right on your laptop. It’s easy to install, fast to start up, and even comes with a web-based dashboard for viewing and managing your deployments.
Open Liberty devfile stack
The Open Liberty devfile stack provides much of the tooling and infrastructure you need to start developing your application. Open Liberty, Maven, Open J9, and more all come packaged in a development image where you build and run your app. A fully configured devfile describes the dev environment and defines all of the build and run commands behind the scenes. You can just sit back and focus on your code.
OpenShift Do (odo)
Odo is a simple CLI tool that you use to create stack projects and interact directly with your Kubernetes cluster (in this case, Minikube). Once you install odo, you can start creating Open Liberty stack projects and developing right in Kubernetes.
Set it up
After installing Minikube, start your local cluster:
$ minikube start
MacOS users might need to start Minikube with a driver other than "docker", due to a known issue with the docker driver and the ingress addon. For example:
$ minikube start --driver=virtualbox
Next, enable the Minikube ingress addon:
$ minikube addons enable ingress
When you enable the ingress addon, you can create a URL for your app by using an ingress domain.
Start the Minikube dashboard (Optional):
$ minikube dashboard
Minikube opens a Kubernetes dashboard in your browser where you can view and interact with your cluster and your development pod.
Try it out
With Minikube set up, you are now ready to create an Open Liberty stack project. You can either initialize an existing application or use the stack starter to create a new app. For this blog, we are going to use the application-stack-intro app. This application is a basic JAX-RS sample that uses Maven, Open Liberty, and MicroProfile.
Clone the following repo and switch to the
$ git clone -b blog-demo [email protected]:OpenLiberty/application-stack-intro.git && \ cd application-stack-intro
Create a new namespace in your Minikube cluster:
$ odo project create ol-app-ns
Initialize the app as a "java-openliberty" stack project:
$ odo create java-openliberty my-ol-comp
You can now see the addition of a
devfile.yaml file in the project root directory that was downloaded from the default devfile registry. This file is the brains behind the Open Liberty devfile stack and it defines the development environment for your app.
Create a URL for the application by using an Ingress domain:
For convenience, you can use the nip.io service to create mappings of your ingress controller to an external IP. Otherwise, you must add the IP to your
$ odo url create --host $(minikube ip).nip.io
Push your app to your local Minikube cluster:
$ odo push
Check the output to make sure that your application is up and ready to use:
$ odo log
You can look for the following message to verify that the server is up:
CWWKF0011I: The server defaultServer is ready to run a smarter planet
To access the application, list the new URL that you created:
$ odo url list Found the following URLs for component my-ol-comp NAME STATE URL PORT SECURE KIND my-ol-comp-9080 Pushed http://my-ol-comp-9080.192.168.99.103.nip.io 9080 false ingress
Open a browser to this URL and append
/api/resource to the end of the URL for the REST endpoint. For example:
Look for the following screen:
You are now ready to start coding! After each change to your app, either re-issue
odo push or run
odo watch to automatically sync your changes with the pod. That’s it!