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: Container Image on Kubernetes.
Prerequisites
To complete this guide, you need:
- 
Complete WildFly Java Microservice - PART 1: Container Image 
- 
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 tborgatowith 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-appPush the my-jaxrs-app Docker Image to it:
podman push quay.io/tborgato/my-jaxrs-appAt 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| Note | You can use wildfly-maven-pluginto automate the image push to an image registry | 
Kubernetes
Minikube
You can use whatever Kubernetes cluster you have available; in this guide, and in the following, we will use minikube.
In case you are using minikube, start the cluster:
minikube startDeploy 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: 9990Deploy to your Kubernetes Cluster:
$ kubectl apply -f deployment-my-jaxrs-app.yaml
deployment.apps/my-jaxrs-app-deployment createdWe 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:30782Verify it’s working as expected:
$ curl http://192.168.39.139:30782/hello/pippo
Hello 'pippo'.