In the first post of this blog series about Verrazzano, I’ve presented how you can install Verrazzano locally to start deploying your applications on it. Now that the Verrazzano has been installed, this blog post will show how to deploy your first microservice into Verrazzano.
When we talk about moving applications to a Cloud Native architecture, we can take two approaches:
- Brownfield – Modernizing an existing application on top of a legacy code.
- Greenfield – New application from the scratch. No legacy code involved.
To demonstrate how Verrazzano is well prepared to support both approaches, we will create an Application composed of two Microservices. One will be written using MicroProfile Helidon to demonstrate the greenfield approach. And the other one will be written using Jakarta EE deployed on a Weblogic Application Server to demonstrate the brownfield approach.
In this blog post, we will create a sample Helidon application from scratch, and deploy it on Verrazzano. Then we will take a look at some capabilities provided by Verrazzano in this sample application.
If you have Maven installed, just execute the following command to generate the project:
mvn -U archetype:generate -DinteractiveMode=false \
-DarchetypeGroupId=io.helidon.archetypes \
-DarchetypeArtifactId=helidon-quickstart-mp \
-DarchetypeVersion=2.4.0 \
-DgroupId=com.rafabene.verrazzano \
-DartifactId=helidon-ms \
-Dpackage=com.rafabene.verrazzano.demo
Now that we have generated the project, we can try it out before publishing it to Verrazzano. Let’s compile, package and execute the project with the following commands:
cd helidon-ms/ mvn package java -jar target/helidon-ms.jar
Leave the application running in one terminal, and open a second one to try this application. Helidon archetype provides a sample “hello world” service that you can invoke, and it will be used to provide a “Greeting service” to the second java service that we will deploy in later using Weblogic. For now, let’s try this Helidon java service using the following command:
curl -X GET http://localhost:8080/greet/Rafael%20Benevides
If you see the result as {“message”:”Hello Rafael Benevides!”}, the application is working fine. Now it’s time to deploy it to Verrazzano.
1 – A brief introduction to OAM (Open Application Model).
One of the biggest differences of Verrazzano in relation to other Kubernetes Platforms is that it automates the wiring of the application with its services through the usage of OAM (Open Application Model). OAM is a runtime-agnostic specification, hosted by CNCF, for defining cloud native applications.
To start using Kubernetes, a Kubernetes user needs to be familiarized with some Kubernetes concepts like Labels, Deployments, Services, Ingress, ConfigMaps, PersistentVolumes, etc. Although the knowledge of these concepts are important to deploy any applications to Verrazzano, any new users will extract much more from Verrazzano if they become also familiar with the Open Application Model. For this reason, before deploying the Helidon application that we just built, let’s understand these five core concepts of OAM:
- Components represent a runnable unit, together with a description.
- Workload types identify the different workloads that a component can execute. Verrazzano provides Helidon, Weblogic and Coherence workloads.
- Traits are overlays that augment a component with additional operations-specific features. Traits represent operator concerns, not developer/software owner concerns. Verrazzano provides Ingress and Metrics traits.
- Application scopes represent application boundaries by grouping components with common properties or dependencies.
- An application configuration assembles a set of component instances, their traits, and the application scopes in which they are placed, combined with configuration parameters and metadata.
Thus, an application is a collection of components with a set of operational traits and scoped together into one or more application boundaries.
Now that we have an idea of what are the parts specified by the Open Application Model, we will deploy the application that has been created to Verrazzano.
2 – Deploying a Component to Verrazzano.
Before deploying any components to Verrazzano, the container image must be available. So, let’s build the container image for this Helidon application, and load it to Kind using the following commands:
docker build -t myrepo/myuser/helidon:1.0 . kind load docker-image myrepo/myuser/helidon:1.0
Another thing that we need is a kubernetes namespace for this application. Let’s create the namespace using the following commands. The second command adds labels identifying the namespace as managed by Verrazzano and enabled for Istio.
kubectl create namespace demo-application kubectl label namespace demo-application verrazzano-managed=true istio-injection=enabled
With the namespace created, create a file called component.yaml with the following content:
apiVersion: core.oam.dev/v1alpha2
kind: Component
metadata:
name: hello-helidon-component
spec:
workload:
apiVersion: oam.verrazzano.io/v1alpha1
kind: VerrazzanoHelidonWorkload
metadata:
name: hello-helidon-workload
labels:
app: hello-helidon
spec:
deploymentTemplate:
metadata:
name: hello-helidon-deployment
podSpec:
containers:
- name: hello-helidon-container
image: "myrepo/myuser/helidon:1.0"
ports:
- containerPort: 8080
name: http
And apply it to the namespace `demo-application` that we just created using the following command:
kubectl apply -n demo-application -f component.yaml
This step causes the validation and creation of the Component resource. No other resources or objects are created as a result. Application configurations applied in the future may reference this Component resource. This means that we need to configure the application using the OAM Application Configuration to finish deploying this component. For this step, create a file called application-config.yaml with the following content:
apiVersion: core.oam.dev/v1alpha2
kind: ApplicationConfiguration
metadata:
name: hello-helidon-appconf
annotations:
version: v1.0.0
description: "Hello Helidon application"
spec:
components:
- componentName: hello-helidon-component
traits:
- trait:
apiVersion: oam.verrazzano.io/v1alpha1
kind: MetricsTrait
spec:
scraper: verrazzano-system/vmi-system-prometheus-0
- trait:
apiVersion: oam.verrazzano.io/v1alpha1
kind: IngressTrait
metadata:
name: hello-helidon-ingress
spec:
rules:
- paths:
- path: "/greet"
pathType: Prefix
Apply it to the namespace `demo-application` just like we did for the OAM component.
kubectl apply -n demo-application -f application-config.yaml
This operation triggers the activation of a number of Verrazzano operators. These operators create other Kubernetes objects (for example, Deployments, ReplicaSets, Pods, Services, Ingresses) that collectively provide and support the application.
3 – Exploring the deployed Component
Before accessing the deployed Component, let’s understand what Verrazzano automatically created in the Kubernetes cluster for us. For this exploration, let’s open the Verrazzano console. More details on how to access the Verrazzano console, and how to get the verrazzano user credentials have been explained in the previous blog post.
However, to make it easy just use the following commands to print the console URLs, and get the verrazzano user credential.
kubectl get vz -o jsonpath="{.items[].status.instance}" | jq .
kubectl get secret \
--namespace verrazzano-system verrazzano \
-o jsonpath={.data.password} | base64 \
--decode; echo
When logging into the Verrazzano console, you should see not only the URL of all other consoles, but a link to the Application and Component that have been deployed.
If you open the VerrazzanoHelidonWorkload (browse to hello-helidon-appconf -> hello-helidon-component -> VerrazzanoHelidonWorkload) we should see that a Kubernetes Deployment, and Service have been created automatically.
If we open the Traits for the deployed Component, we should see also that a Certificate, an Istio Gateway, and an Istio VirtualService have been also automatically created.
3.1 – Verrazzano Metrics trait
Because we enabled Metrics traits in the Application Configuration, Verrazzano will also collect the metrics from Helidon and start sending them to Prometheus and Grafana. Note that it was not needed to inform where the metrics of this component are. It simply works based on the Workload type.
If we open the Prometheus console, we can add the following query to see how many requests were made to the application. Try it, and leave it opened to see the number of requests increasing as we access the application.
base_REST_request_total{method="getDefaultMessage"}
It’s also possible to open Grafana and select the Helidon Monitoring Dashboard to see more information about the component that has been deployed.
4 – Accessing the application
As we saw in the previous section of this blog, because an IngressTrait has been deployed, Verrazzano created, among other resources, an Istio Gateway. To access the application we need to find the DNS hostname to this application.
Usually it will have the following pattern:
ApplicationConfigurationName.Namespace.VerrazzanoDomain
Let’s get the hostname by querying the Istio Gateway for this component, and access the application.
HOST=$(kubectl get gateway -n demo-application \
demo-application-hello-helidon-appconf-gw \
-o jsonpath='{.spec.servers[0].hosts[0]}')
echo $HOST
curl -sk \
-X GET \
"https://${HOST}/greet/Rafael"
You should see the message: {“message”:”Hello Rafael!”}
Don’t forget to return to the Prometheus console to see the update in the number of requests.
5 – Conclusion
In this blog post you saw how easy it is to start developing a microservices application in a greenfield approach using Helidon and Verrazzano. Verrazzano accelerates application development productivity and innovation, and brings several cloud native benefits without lock-in. This is granted by a cloud-neutral approach to achieve the same observability and lifecycle benefits regardless of deploying on premises, on Oracle Cloud Infrastructure, or on other public clouds.
Check out more details about Verrazzano on its webpage: https://verrazzano.io and https://www.oracle.com/java/verrazzano/ . At the Verrazzano’s Youtube channel, you will see a Verrazzano tour video and much more. News about this project is shared on Verrazzano’s Twitter profile. Verrazzano is a fast paced evolving open source project. You can follow, and also contribute to this awesome project on the Github project page. Keep in touch with this blog post series. The next blog post you will see how to use Verrazzano to embrace a brownfield approach empowering an existing Weblogic Java application.
