Deploy IBM OpenLiberty apps onto Kubernetes using Eclipse JKube

Eclipse JKube deploying OpenLiberty app into Kubernetes

What is OpenLiberty?

OpenLiberty is a really lightweight open-source framework for building fast and efficient cloud-native Java applications. It allows Java developers to configure only needed features, resulting in small memory consumption. It’s one of the few cloud-native Java frameworks that support Docker and Kubernetes.

Setting up Kubernetes:

We would be deploying one of the OpenLiberty Getting started guide onto Kubernetes using the Eclipse JKube. But first, we need to make sure our Kubernetes Cluster is running. I am using minikube so I started it using this command:

minikube start
# To point your shell to minikube's docker-daemon, run:
eval $(minikube -p minikube docker-env)

Getting OpenLiberty Quickstart Guide:

Now we have got all the essential setup we need to deploy our application onto Kubernetes. We’re using OpenLiberty Getting Started Guide. It contains two projects start and finish, but we’ll only consider finish since it’s the end result of the guide:

git clone
cd guide-getting-started/finish
mvn clean install

Deploying to Kubernetes:

In order to deploy application onto Kubernetes, we would add Eclipse JKube’s Kubernetes Maven Plugin to pom.xml’s plugins section:


Containerizing the application into a Docker image:

We can now use Eclipse JKube in our project, let’s start by containerizing this application into a Docker image. If you notice carefully, this sample already has a Dockerfile in its root folder. Eclipse JKube detects Dockerfiles automatically and does a plain docker build based on that Dockerfile. We only need to do minor modifications inside the Dockerfile so that it is Eclipse JKube can work with it without any problems.

Modifying project files’ relative path in Dockerfile and exposing ports
finish : $ mvn k8s:build
[INFO] Scanning for projects...
[INFO] -----< io.openliberty.guides:guide-getting-started >-----
[INFO] Building guide-getting-started 1.0-SNAPSHOT
[INFO] --------------[ war ]---------------------------------
[INFO] --- kubernetes-maven-plugin:1.0.0-rc-1:build (default-cli) @ guide-getting-started ---
[INFO] k8s: Running in Kubernetes mode
[INFO] k8s: Building Docker image in Kubernetes mode
[INFO] k8s: [guides/guide-getting-started:latest]: Created docker-build.tar in 10 seconds
[INFO] k8s: [guides/guide-getting-started:latest]: Built image sha256:424e8
[INFO] k8s: [guides/guide-getting-started:latest]: Removed old image sha256:ad954
[INFO] --------------------------------------------------------------------
[INFO] --------------------------------------------------------------------
[INFO] Total time: 01:35 min
[INFO] Finished at: 2020-08-22T19:46:23+05:30
[INFO] --------------------------------------------------------------------
finish : $ docker images | grep guide-getting-started
guides/guide-getting-started latest 424e87972dcb 6 min ago 741MB

Generating and applying Kubernetes manifests:

Now that your image is built, you can go ahead and generate resource manifests for your project. Eclipse JKube checks image ports and generates opinionated Service and Deployment. if you want to customize it, you can provide custom YAML fragments in src/main/jkube directory or using XML configuration. I will be using two properties to override some Service configuration:

finish : $ mvn k8s:resource k8s:apply
[INFO] Scanning for projects...
[INFO] ------< io.openliberty.guides:guide-getting-started >--------
[INFO] Building guide-getting-started 1.0-SNAPSHOT
[INFO] ----------------------[ war ]-------------
[INFO] --- kubernetes-maven-plugin:1.0.0-rc-1:resource (default-cli) @ guide-getting-started ---
[INFO] k8s: jkube-controller: Adding a default Deployment
[INFO] k8s: jkube-service: Adding a default service 'guide-getting-started' with ports [9080]
[INFO] k8s: jkube-revision-history: Adding revision history limit to 2
[INFO] k8s: validating /home/rohaan/work/repos/openliberty-guide-getting-started/finish/target/classes/META-INF/jkube/kubernetes/guide-getting-started-service.yml resource
[INFO] k8s: validating /home/rohaan/work/repos/openliberty-guide-getting-started/finish/target/classes/META-INF/jkube/kubernetes/guide-getting-started-deployment.yml resource
[INFO] --- kubernetes-maven-plugin:1.0.0-rc-1:apply (default-cli) @ guide-getting-started ---
[INFO] k8s: Using Kubernetes at in namespace default with manifest /home/rohaan/work/repos/openliberty-guide-getting-started/finish/target/classes/META-INF/jkube/kubernetes.yml
[INFO] k8s: Using namespace: default
[INFO] k8s: Creating a Service from kubernetes.yml namespace default name guide-getting-started
[INFO] k8s: Created Service: target/jkube/applyJson/default/service-guide-getting-started-1.json
[INFO] k8s: Creating a Deployment from kubernetes.yml namespace default name guide-getting-started
[INFO] k8s: Created Deployment: target/jkube/applyJson/default/deployment-guide-getting-started-1.json
[INFO] k8s: HINT: Use the command `kubectl get pods -w` to watch your pods start up
[INFO] --------------------------------------------------------------------[INFO] BUILD SUCCESS
[INFO] --------------------------------------------------------------------[INFO] Total time: 8.726 s
[INFO] Finished at: 2020-08-22T20:02:47+05:30
[INFO] --------------------------------------------------------------------
finish : $

Checking deployed application running in Kubernetes:

You can check whether application got deployed using kubectl:

Checking application pods running in Kubernetes after jkube deploy
finish : $ minikube service guide-getting-started|-----------|-------------|-------------|--------------------------|
| NAMESPACE | NAME| TARGET PORT | URL | |-----------|-------------|-------------|--------------------------|
| default | guide-getting-started | glrpc/9080 | |
🎉 Opening service default/guide-getting-started in default browser...
OpenLiberty Geting started sample running inside minikube(output of minikube service)
mvn k8s:log
mvn k8s:undeploy



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store