WildFly Java Microservice - PART 2: Kubernetes
In this guide, you will learn HOW-TO run the Docker Image you built in WildFly Java Microservice - PART 1: Docker Image on Kubernetes.
Prerequisites
To complete this guide, you need:
-
A Kubernetes cluster: throughout this mini-series, we will use Minikube
Image Registry
To make the my-jaxrs-app:latest
Docker Image available to Kubernetes, you need to push it to some Image Registry that is accessible by the Kubernetes cluster you want to use.
Quay.io
There are many Image Registries you can use: in this guide, we will push the my-jaxrs-app:latest
Docker Image, to the quay.io Image Registry.
Create a public repository named my-jaxrs-app
on quay.io (e.g. https://quay.io/repository/tborgato/my-jaxrs-app).
Note
|
replace tborgato with the name of your account in all the commands that will follow
|
Tag the Docker image:
podman tag my-jaxrs-app quay.io/tborgato/my-jaxrs-app
Push the my-jaxrs-app
Docker Image to it:
podman push quay.io/tborgato/my-jaxrs-app
At this point, the my-jaxrs-app:latest
Docker Image should be publicly available and free to be consumed by any Kubernetes Cluster; you can verify this by running:
podman pull quay.io/tborgato/my-jaxrs-app
Kubernetes
Minikube
You can use whatever Kubernetes cluster you have available; in this guide, and in the following, we will use minikube.
Deploy to Kubernetes
To deploy our quay.io/tborgato/my-jaxrs-app
Docker image to Kubernetes, create a file named deployment-my-jaxrs-app.yaml
(see kubernetes deployment) in the same directory as the Dockerfile
and the pom.xml
file, with the following content:
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-jaxrs-app-deployment
labels:
app: my-jaxrs-app
spec:
replicas: 1
selector:
matchLabels:
app: my-jaxrs-app
template:
metadata:
labels:
app: my-jaxrs-app
spec:
containers:
- name: my-jaxrs-app
image: quay.io/tborgato/my-jaxrs-app
ports:
- containerPort: 8080
- containerPort: 9990
livenessProbe:
httpGet:
path: /health/live
port: 9990
readinessProbe:
httpGet:
path: /health/ready
port: 9990
startupProbe:
httpGet:
path: /health/started
port: 9990
Deploy to your Kubernetes Cluster:
$ kubectl apply -f deployment-my-jaxrs-app.yaml
deployment.apps/my-jaxrs-app-deployment created
We used minikube as Kubernetes Cluster, hence we expose the deployment as NodePort
:
$ kubectl expose deployment.apps/my-jaxrs-app-deployment --type=NodePort --port=8080
service/my-jaxrs-app-deployment exposed
Note
|
you can also use Helm Chart for WildFly to deploy your application |
Check your application
Find out on what IP address/port, minikube is exposing your service:
$ minikube service my-jaxrs-app-deployment --url
http://192.168.39.139:30782
Verify it’s working as expected:
$ curl http://192.168.39.139:30782/hello/pippo
Hello 'pippo'.