Skip to content
Kubernetes Operator for WildFly
Branch: master
Clone or download
jmesnil Merge pull request #15 from jmesnil/olm-catalog_0.1.0
OLM Catalog for WildFly Operator 0.1.0
Latest commit afc71d6 Jun 11, 2019

README.adoc

Docker Repository on Quay Build Status Go Report Card Join Chat

WildFly Operator for Kubernetes/OpenShift

The WildFly Operator for Kubernetes provides easy monitoring and configuration for Java applications deployed on WildFly application server using the Source-to-Image (S2I) template for WildFly.

Once installed, the WildFly Operator provides the following features:

  • Create/Destroy: Easily launch an application deployed on WildFly

  • Simple Configuration: Configure the fundamentals of WildFly-based application including number of nodes, application image, etc.

Custom Resource Definitions

The operator acts on the following Custom Resource Definitions (CRDs):

  • WildFlyServer, which defines a WildFly deployment. The Spec and Status of this resources are defined in the API documentation.

Quickstart

Install the Operator and associate resources:

The examples require that Minikube is installed and running.

# Install resources for the WildFly Operator
$ kubectl apply -f deploy/service_account.yaml
$ kubectl apply -f deploy/role.yaml
$ kubectl apply -f deploy/role_binding.yaml
# install WildFlyServer CRD
$ kubectl apply -f deploy/crds/wildfly_v1alpha1_wildflyserver_crd.yaml
# install WildFly Operator
$ kubectl create -f deploy/operator.yaml

Install a custom resource

An example of a custom resource of WildFlyServer is described in quickstart-cr.yaml:

apiVersion: wildfly.org/v1alpha1
kind: WildFlyServer
metadata:
  name: quickstart
spec:
  applicationImage: "quay.io/jmesnil/wildfly-operator-quickstart:16.0"
  size: 2
  storage:
    volumeClaimTemplate:
      spec:
        resources:
          requests:
            storage: 3Gi
Note

It is based on the S2I application image jmesnil/wildfly-operator-quickstart:16.0 that provides a simple Java Web application wildfly-operator-quickstart on top of WildFly 16.0.0.Final which returns the IP address of its host:

$ curl http://localhost:8080/
{"ip":"172.17.0.3"}

This simple application illustrates that successive calls will be load balanced across the various pods that runs the application.

$ kubectl create -f deploy/crds/quickstart-cr.yaml
wildflyserver.wildfly.org/quickstart created

Once the application is deployed, it can be accessed through a load balancer:

$ curl $(minikube service quickstart-loadbalancer --url)
{"ip":"172.17.0.7"}
$ curl $(minikube service quickstart-loadbalancer --url)
{"ip":"172.17.0.8"}
$ curl $(minikube service quickstart-loadbalancer --url)
{"ip":"172.17.0.7"}

As illustrated above, calls to the application are load balanced across the pods that runs the application image (as we can see from the different IP addresses).

The WildFly operator describes the deployed application with $ kubectl describe wildflyserver quickstart:

Name:         quickstart
Namespace:    default
Labels:       <none>
Annotations:  <none>
API Version:  wildfly.org/v1alpha1
Kind:         WildFlyServer
Metadata:
  Creation Timestamp:  2019-04-09T08:49:24Z
  Generation:          1
  Resource Version:    7954
  Self Link:           /apis/wildfly.org/v1alpha1/namespaces/default/wildflyservers/quickstart
  UID:                 5feb0fd3-5aa4-11e9-af00-7a65e1e4ff53
Spec:
  Application Image:  quay.io/jmesnil/wildfly-operator-quickstart:16.0
  Size:               2
  Storage:
    Volume Claim Template:
      Spec:
        Resources:
          Requests:
            Storage:  3Gi
Status:
  Pods:
    Name:    quickstart-0
    Pod IP:  172.17.0.7
    Name:    quickstart-1
    Pod IP:  172.17.0.8
Events:      <none>

The Status section is updated with the 2 pods names containing the application image.

You can modify this custom resource spec to scale up its size from 2 to 3:

$ kubectl edit wildflyserver quickstart
# Change the `size: 2` spec to `size: 3` and save

wildflyserver.wildfly.org/quickstart edited

The deployment will be updated to scale up to 3 Pods and the resource Status will be updated accordingly:

$ kubectl describe wildflyserver quickstart
Name:         quickstart
Namespace:    default
Labels:       <none>
Annotations:  <none>
API Version:  wildfly.org/v1alpha1
Kind:         WildFlyServer
Metadata:
  Creation Timestamp:  2019-04-09T08:49:24Z
  Generation:          2
  Resource Version:    8137
  Self Link:           /apis/wildfly.org/v1alpha1/namespaces/default/wildflyservers/quickstart
  UID:                 5feb0fd3-5aa4-11e9-af00-7a65e1e4ff53
Spec:
  Application Image:  quay.io/jmesnil/wildfly-operator-quickstart:16.0
  Size:               3
  Storage:
    Volume Claim Template:
      Spec:
        Resources:
          Requests:
            Storage:  3Gi
Status:
  Pods:
    Name:    quickstart-0
    Pod IP:  172.17.0.7
    Name:    quickstart-1
    Pod IP:  172.17.0.8
    Name:    quickstart-2
    Pod IP:  172.17.0.9
Events:      <none>

You can then remove this custom resource and its assocated resources:

$ kubectl delete wildflyserver quickstart

wildflyserver.wildfly.org "quickstart" deleted

OpenShift

The examples can also be installed in OpenShift and requires a few additional steps.

The instructions requires that Minishift is installed and running.

Deploying the operator and its resources by executing the following commands:

$ oc login -u system:admin
$ oc adm policy add-cluster-role-to-user cluster-admin developer
$ oc apply -f deploy/service_account.yaml
$ oc apply -f deploy/role.yaml
$ oc apply -f deploy/role_binding.yaml
$ oc apply -f deploy/crds/wildfly_v1alpha1_wildflyserver_crd.yaml
$ oc apply -f deploy/operator.yaml

$ oc login -u developer

After installing the WildFlyServer resource from deploy/crds/quickstart-cr.yaml, you have to create a route to expose it from OpenShift:

$ oc expose svc/quickstart-loadbalancer

route.route.openshift.io/quickstart-loadbalancer exposed

This will expose the service from OpenShift. To know the URL of the exposed service, run:

$ oc get route quickstart-loadbalancer --template='{{ .spec.host }}'

This will display the host of the route (on my local machine, it displays quickstart-loadbalancer-myproject.192.168.64.16.nip.io).

The application can then be accessed by running:

$ curl "http://$(oc get route quickstart-loadbalancer --template='{{ .spec.host }}')"
{"ip":"172.17.0.9"}

Developer Instructions

System Requirements

Building the WildFly Operator

  1. Add the source under $GOPATH:

    $ git clone https://github.com/wildfly/wildfly-operator.git $GOPATH/src/github.com/wildfly/wildfly-operator
  2. Change to the source directory.

    $ cd $GOPATH/src/github.com/wildfly/wildfly-operator
  3. Review the available build targets.

    $ make
  4. Run any build target. For example, compile and build the WildFly Operator with:

    $ make build
You can’t perform that action at this time.