This repository contains the code to build a nexus Operator for Kubernetes, including Red Hat OpenShift Container Platform.
The Operator will create an instance of Nexus Repository Manager.
It is implemented on top of the Red Hat Operator SDK - in particular the Ansible Operator.
There is a script develop/operate.sh
which will download the prerequisites (operator-sdk etc.), build the operator artifacts from operator-sdk defaults, package and push the operator container image, deploy the artifacts to a Kubernetes cluster, and create a kind: Nexus
CR to deploy an instance. You should use the help page to look at what the various options do, but for the most part if you want to deploy Nexus to a cluster directly from this repo you could run develop/operate.sh -d
.
Before running the script make sure to update the location of the container image to a repository you have access to. If you decide to build your own container image for the operator, make sure to update develop/operate.conf
with an updated container image location and add the -p
flag to operate.sh
.
The installation of the Custom Resource Definition and Cluster Role requires cluster-admin privileges. After that regular users with admin
privileges on their projects (which is automatically granted to the user who creates a project) can provision the Nexus Operator in their projects and deploy instances of nexus using the nexus.redhatgov.io Custom Resource.
Perform the following tasks as cluster-admin:
-
Deploy the CustomResourceDefinition, ClusterRole, ClusterRoleBinding, ServiceAccount, and Operator Deployment:
develop/operate.sh
-
Once the Operator pod is running the Operator is ready to start creating Nexus Servers.
-
To deploy the above, and also one of the
config/samples/redhatgov_v1alpha1_nexus*.yaml
example CustomResources:develop/operate.sh --deploy-cr
-
To install the operator with RBAC scoped to a specific namespace, deploying a Role and RoleBinding instead of a ClusterRole and ClusterRoleBinding:
develop/operate.sh --overlay=namespaced --namespace=mynamespace
A nexus instance is deployed by creating a Custom Resource based on the nexus Custom Resource Definition.
apiVersion: redhatgov.io/v1alpha1
kind: Nexus
metadata:
name: nexus-sample
spec:
nexus:
expose:
ssl: true # There is currently no way to specify an alternate certificate
uri: nexus-sample.example.com # You can leave this field out on OpenShift to get the default
kind: Ingress # This can be of kind Route on OpenShift (the default)
oauth: false
image:
src: registry.connect.redhat.com/sonatype/nexus-repository-manager
tag: latest
pullPolicy: Always
volumeSize: 10Gi
persistent: true
-
Write the definition to a file (e.g. nexus.yaml) and then create the Nexus instance:
oc create -f ./nexus.yaml
-
You can validate the existence of your nexus instance by querying for nexus objects:
oc get nexus
-
Get the Route for nexus:
oc get route
-
The admin user credentials are stored in a secret. The secret is created once nexus comes online. In the example above, the nexus repo is named nexus-sample, so the secret is called nexus-sample-admin-credentials
-
Use
to see the base64 encoded values of the admin username and password.oc get -o yaml secret nexus-sample-admin-credentials
-
Decode the values and use them to login to the nexus repo.
Deleting a Nexus instance and its associated resources is as simple as deleting the nexus object. If you created a nexus server called nexus-example
as in the example above it suffices to run the delete command on that resource:
oc delete nexus nexus-example
The Operator adds ownerReference fields to all created objects - which means that deleting the nexus object also deletes all objects that have been created by the Operator.
In case you wish to uninstall the nexus Operator make sure that there are no more nexus instances running. Once all nexus instances have been deleted simply delete the operator and its resources with:
develop/operate.sh --remove
The Operator SDK makes heavy use of Kustomize for development and installation, but intends bundles to be generated for use in an operator catalog. This enables the Operator Lifecycle Manager, deployed onto your cluster, to install and configure operators with a simple kind: Subscription
object, instead of a large collection of manifests. If you intend on using develop/operate.sh
it expects you to be in a development environment. Operator installation from this script therefore expects access to the internet. This comes with one extra concern: If kustomize
isn’t in your path, it tries to download it from the internet and save it locally into a .gitignore`d folder. If you intend on using `develop/operate.sh
to install the operator, you should also bring kustomize
and place it in the $PATH
of the user who will be running the script.
To change the image sources for all necessary images for develop/operate.sh
to deploy the operator, you need to have the following images hosted in a container repository on your disconnected network:
-
quay.io/redhatgov/nexus-operator:latest
-
registry.connect.redhat.com/sonatype/nexus-repository-manager:latest
-
registry.access.redhat.com/ubi8/ubi-minimal:latest
-
registry.redhat.io/openshift4/ose-oauth-proxy:latest
The places where you must update those sources are then, respectively:
-
develop/operate.conf
: IMG should point to the nexus-operator image in your environment before runningdevelop/operate.sh
-
The
kind: nexus
custom resource manifest:spec.nexus.image.src
andspec.nexus.image.tag
should be updated