Quarkus on Kubernetes

For the last couple of months I’ve been working on a hobby project to get insights in my banking transactions. Developing and using this application was always only on my local machine. The goal is, however, to make it usable for the public. So it needs to be deployed somewhere.

As I’m learning Kubernetes, it’s only logical to deploy my application on a nice Kubernetes cluster. The first step is to deploy the application to a locally running Kubernetes cluster. I could then pick it up and deploy is somewhere else. As it turns out, it’s really easy to create a Docker image and a kubernetes manifest using Quarkus extensions.

Quarkus

Quarkus provides a whole list of extentions to make the live of a developer easier. Thees extensions are nothing more than some standard pieces of config to your Gradle of Maven project. By adding the extension, it adds the proper dependency, plugin and some default config.

To generate a Docker image, add the jib extension: quarkus extension add jib

To generate the Kubernetes deployment manifest, add the kubernetes extension quarkus extension add kubernetes

Build the docker image and kubernetes manifest ./gradlew build -Dquarkus.container-image.build=true

Kubernetes

Normally we should push the docker image to a registry, but that would be the next step for me. First, I want to be able to deploy locally. In order to do that we need to change the generated Kubernetes manifest slightly. We need to tell it that it shouldn’t try to pull the image from the registry, but use the locally generated one. To do this set the imagePullPolicy to Never

spec:
  containers:
    - env:
        - name: KUBERNETES_NAMESPACE
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace
      image: docker.io/paulvandenberg/backend:1.0-SNAPSHOT
      imagePullPolicy: Never

Now we can deploy the app using this command: kubectl apply -f build/kubernetes/kubernetes.yaml