Jolie Microservices on Kubernetes
Jolie is a "microservice-oriented" programming languages: it crystallizes the programming concepts of microservices as native language features.
Join the DZone community and get the full member experience.Join For Free
The Jolie programming language is (micro)service-oriented: it makes it easy to create services and plays well with containerization. Deploying a Jolie service in a Docker container is quite easy.
In this article, we are going to deploy a Jolie service on Kubernetes and invoke it in four easy steps.
This is a little demo on how to set up a Kubernetes environment on your PC (thanks to minikube) and build up a scalable clusterized version of a simple Jolie service.
What we are going to do now is to transform the example service for doubling numbers from the Jolie documentation into a powerful Kubernetes scalable app (doing exactly the same thing, but with the power of the cloud, so cooler).
First of all, let's set up our box!
Make sure that you have:
Now you can clone this Git repository and go ahead.
Step 1: Create a Docker Image Containing Your Jolie Application
This task is very simple, following the official Jolie documentation and using images available on Docker Hub.
This is our Dockerfile to build an image exposing the "twice-a-number" service on TCP port 8000:
Before creating the image we have to configure Docker's environment to point to minikube, otherwise images wouldn't be available to your local cluster.
Win10 (on PowerShell)
Ok, now we can build our image (if not specified, commands are the same on both platforms; don't miss the final dot),
Now, verify that all went as expected:
Step 2: Create a Kubernetes Deployment
We are ready to use our brand new image in a Kubernetes deployment. We set the "replicas" parameter to 2, meaning that Kubernetes will always have two pods running our container.
To start deployment rollout, just type:
$ kubectl apply -f jolie-k8s-deployment.yml
And after a few seconds you will see your pods up and running:
Step 3: Expose Deployment by a Service
Now we have two running instances of our (micro)service, but we lack a communication channel to reach the container's port 8000 from outside of the Kubernetes virtual network.
Kubernetically speaking we need a service.
Following the minikube tutorial, we type:
So now there's a service exposing the pod's port 8000 on the cluster's port 30095.
To make this visible from your host, you have to go through a "minikube service":
The service is now visible and ready to receive invocations!
Step 4: Invoke Microservices From a Client
As a final step, we make sure that everything is working by calling the Jolie service running inside the Kubernetes cluster.
Open client.ol with a text editor and modify line 5, setting the IP and port of exposed the minikube service:
Save and try the following:
As you can, see we are getting the right response (client.ol has a hardcoded value 5 as an input) and so we have successfully demonstrated that Kubernetes can at least multiply an integer by another integer!
In our source code, we modified server.ol from the original to write out the hostname too:
getenv@Runtime( "HOSTNAME" )( hostname_env )
result = hostname_env + " -> " + number * 2
And that allow us to verify that:
- Our Jolie server is running on multiple pods.
- The infrastructure is hidden from the clients.
- The calls are automatically managed and balanced by the Kubernetes engine (the output shows each call is getting its response from a different pod).
- BONUS: if you need more power to twice number 5 you can scale up your deployment by running the following command.
$ kubectl scale deployment jolie-sample-deployment --replicas=<N
Enjoy your Jolie services on Kubernetes!
Published at DZone with permission of Marco Montesi. See the original article here.
Opinions expressed by DZone contributors are their own.