in Payara Kubernetes ~ read.

Running Payara in Kubernetes

In the first part of hopefully longer series I will focus at the tasks one should do to get plain server — without the app, but a Java EE full profile one — up and running in Kubernetes cluster.

Installing the tools

For this series I will be using my Windows 10 Home notebook. Particulary important consequence of that is, that Hyper-V is not availble. I will therefore use VirtualBox.

Step 1: Install VirtualBox

There’s not much to be said to this one, just head over to VirtualBox download page, download and install.

Step 2: Install Kubernetes

Kubernetes is a tool for (virtual machine) clusters. However, you can run it all in single virtual machine on your computer! To achieve that you’ll need:

  • minikube: the management tool for the vm. Download minikube-windows-amd64.exe, put it in a dedicated folder for your kubernetes tools, and rename it to minikube.exe

  • kubectl: CLI tool for interacting with Kubernetes. They have fancy bash & curl script for downloading the current release, I’m pretty sure it’s almost of no use for you, the Windows guy. Here’s bit of PowerShell instead:

    $(
      $base = "https://storage.googleapis.com/kubernetes-release/release";
      $ver = iwr "$base/stable.txt" | % { $_.Content.Trim() };
      "$base/$ver"
    ) | % {
      iwr "$_/bin/windows/amd64/kubectl.exe" -OutFile kubectl.exe
    }

Create and run the cluster

We’re just few commands away from running the cluster now.

Step 3: Prepare Environment vars

On typical home machine, you don’t need to set any variables. However, on "enterprise" one you might consider:

:: We will download some ISOs now
SET https_proxy=http://proxy.company.local:8080
:: Into directory %MINIKUBE_HOME%\.minikube, defaults to %HOMEPATH%.
:: Also a vm disk image gets created there
:: it also fails if you're not running minikube on your HOMEDRIVE
SET MINIKUBE_HOME=d:\src\kubernetes

Step 4: Create cluster

d:\src\kubernetes>minikube start --vm-driver=virtualbox
Starting local Kubernetes v1.6.0 cluster...
Starting VM...
Downloading Minikube ISO
 89.51 MB / 89.51 MB [==============================================] 100.00% 0s
SSH-ing files into VM...
Setting up certs...
Starting cluster components...
Connecting to cluster...
Setting up kubeconfig...
Kubectl is now configured to use the cluster.

You can see virtual machine minikube running in VirtualBox now. Let’s check, that it indeed works:

d:\src\kubernetes>kubectl cluster-info
Kubernetes master is running at https://192.168.99.100:8443

To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.

d:\src\kubernetes>minikube dashboard
Opening kubernetes dashboard in default browser...
c2301036 400c 11e7 8a3f 7c1a249a8624.png

Deploy Payara

Step 5: Create deployment

Bare deployment of Payara inside cluster can be achieved with

> kubectl run payara --image=payara/server-full --port=8080 --replicas 1
deployment "payara" created

This starts download of a docker image and creates a Deployment and a Replica Set, that in turn contains single Pod, that exposes standard HTTP port. It will take a while, since the docker image needs to be downloaded. You can monitor the progress like this:

> kubectl get events
LASTSEEN   FIRSTSEEN   COUNT     NAME                      KIND         SUBOBJECT                 TYPE      REASON              SOURCE                  MESSAGE
6m         6m          1         payara-4223602339-vr5w5   Pod                                    Normal    Scheduled           default-scheduler       Successfully assigned payara-4223602339-vr5w5 to minikube
6m         6m          1         payara-4223602339-vr5w5   Pod          spec.containers{payara}   Normal    Pulling             kubelet, minikube       pulling image "payara/server-full"
6m         6m          1         payara-4223602339         ReplicaSet                             Normal    SuccessfulCreate    replicaset-controller   Created pod: payara-4223602339-vr5w5
6m         6m          1         payara                    Deployment                             Normal    ScalingReplicaSet   deployment-controller   Scaled up replica set payara-4223602339 to 1

Alternatively you can use minikube dashboard for more interactive view.

Step 6: Expose HTTP port

After the replica set is running, you yet need to make it accessible from within container inside minikube VM to your host:

> kubectl expose deployment payara --port=80 --type=NodePort
service "payara" exposed
> minikube service payara
Opening kubernetes service default/payara in default browser...
e607bc24 40c6 11e7 80b7 a4ea7b632e3a.png

Six steps are already enough for a nice evening spent at your computer, in next part of the series we’ll try to draw the rest of the owl:

  • Deploying the app into server, ideally without every build result being 800MB

  • Improving logging

  • Customizing your domain

  • …​

Stay tuned! 

comments powered by Disqus