image:https://github.com/wildfly/wildfly-operator/actions/workflows/go.yml/badge.svg?branch=main["Go",link="https://github.com/wildfly/wildfly-operator/actions/workflows/go.yml"] image:https://quay.io/repository/wildfly/wildfly-operator/status?token=c568da69-fcdb-4b58-8821-5e98f6522290["Docker Repository on Quay", link="https://quay.io/repository/wildfly/wildfly-operator"] image:https://goreportcard.com/badge/github.com/wildfly/wildfly-operator["Go Report Card", link="https://goreportcard.com/report/github.com/wildfly/wildfly-operator"] image:https://img.shields.io/badge/zulip-join_chat-brightgreen.svg["Join Chat", link="https://wildfly.zulipchat.com/"]
The WildFly Operator for Kubernetes provides easy monitoring and configuration for Java applications deployed on http://wildfly.org[WildFly application server] using the https://github.com/wildfly/wildfly-s2i[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.
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 https://github.com/wildfly/wildfly-operator/blob/main/doc/apis.adoc[API documentation].The examples require that https://kubernetes.io/docs/setup/minikube/[Minikube] is installed and running.
$ make install
An example of a custom resource of WildFlyServer
is described in https://github.com/wildfly/wildfly-operator/blob/main/config/samples/quickstart-cr.yaml[quickstart-cr.yaml]:
It is based on the S2I application image https://quay.io/repository/wildfly-quickstarts/wildfly-operator-quickstart[jmesnil/wildfly-operator-quickstart:18.0] that provides a simple Java Web application https://github.com/jmesnil/wildfly-operator-quickstart[wildfly-operator-quickstart] on top of WildFly 18.0.0.Final which returns the IP address of its host:
Once the application is deployed, it can be accessed through a load balancer:
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
:
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 replicas from 2
to 3
:
$ kubectl edit wildflyserver quickstart
replicas: 2
spec to replicas: 3
and saveThe deployment will be updated to scale up to 3 Pods and the resource Status
will be updated accordingly:
You can then remove this custom resource and its associated resources:
$ kubectl delete wildflyserver quickstart
The examples can also be installed in OpenShift and requires a few additional steps.
The instructions require that https://github.com/minishift/minishift[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 $ make install $ make deploy
When a WildFlyServer
resource is installed from config/samples/quickstart-cr.yaml
, a route
is automatically created to expose the application. To know the URL of the exposed service, run:
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:
$GOPATH
:
$ git clone https://github.com/wildfly/wildfly-operator.git $GOPATH/src/github.com/wildfly/wildfly-operator
$ cd $GOPATH/src/github.com/wildfly/wildfly-operator
$ make
$ make build
The Operator can run in two modes:
The following commands run the Operator as a local application and deploy the quickstart on minikube:
make install
builds the CRD by using kustomize. +
make run
will build the Operator and run it as a local application. +
You have to define the namespace you want to watch for changes by specifying the WATCH_NAMESPACE
environment variable.
The following command removes the quickstart custom resource:
You can stop the Operator by using CTL-C.
If you want to Debug the Operator code in Local Mode, use make debug
instead of make run
:
This target will download https://github.com/go-delve/delve[Delve] and will start the Operator listening at 2345 port. You can later attach a debugger from your IDE.
In this mode you need to build the Operator, push its image in a public container registry, and deploy it as a regular resource.
To build the Operator image and push it to https://quay.io/[quay.io], execute the following command:
To deploy this image in your cluster and deploy the quickstart example, execute the following:
To remove the quickstart custom resource, execute the following:
To remove the Operator from your cluster, execute the following:
To run the e2e tests you need to have a cluster accessible from your local machine and have logged in as kubeadmin.
This is useful for development since you don’t need to build and push the Operator image to a docker registry. The Operator will be deployed as a local application. Execute the following to run the test suite deploying the Operator as a local application:
The test suite creates the resources for each test under the wildfly-op-test-ns
namespace.
You can monitor the resources created by the test suite in a different terminal window by issuing:
Note: Transaction recovery tests will be skipped under this mode since they cannot run outside the cluster.
In this mode, the Operator will run in Deploy Mode, so you need to have the latest Operator image available somewhere. Before running the e2e tests. Execute the following to build and push the Operator you want to test to a public container registry, for example to https://quay.io/[quay.io]
Once you have your Operator image publicly accessible, run the tests specifying the location of the Operator image under test:
The test suite creates the resources for each test under the wildfly-op-test-ns
namespace.
You can monitor the resources created by the test suite in a different terminal window by issuing:
You can also install the Operator by using OLM. This could be useful to verify how changes in the CSV will be applied. The following instructions describes how to prepare the Operator image, bundle and catalog to deploy the Operator in a cluster that uses OML. The example commands use https://quay.io/[quay.io] as container registry and OpenShift as kubernetes cluster:
Execute the following command to build the Operator image, bundle and catalog:
manifests docker-build docker-push
: Creates the Operator image and push it to your container registry.bundle bundle-build bundle-push
: Builds a bundle with the resources needed by the operator. You can
modify the autogenerated CSV by looking at bundle/manifests/
directory.catalog-build catalog-push
: Creates a catalog containing the bundled Operator.Then deploy a CatalogSource
which contains information for accessing a repository of Operators.
When using OpenShift, the catalog source needs to be created on the openshift-marketplace
namespace:
Wait until your Operator is recognized by OLM:
Once the operator is recognised by OML, you can install the Operator from the OpenShift web console or by the command line creating a Subscription and an OperatorGroup resource:
The Operator will be installed on the current namespace.