rohanKanojia / librarybookoperatorinjava

A Simple Kubernetes Operator following Library's Book issue/return mechanism using Quarkus Kubernetes Client Extension

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Simple Kubernetes Operator demonstrating Library Management

This is a simple demo Kubernetes Operator written to mimic Library Management using Quarkus Fabric8 Kubernetes Client Extension. It operates on the following Custom Resources:

  • Book
  • BookIssueRequest

Scenarios Considered:

  • User creates a BookIssueRequest which updates the requested Book setting it's issued status to true and updating issuedTo section in Book's status.

  • On Deleting any BookIssueRequest, Book is updated again and is marked available for issue(by setting issued status to false

  • Any update in BookIssueRequest object would update specified Book resource in case it's different from previous value

Both Book and BookIssueRequest CustomResources are watched in specified namespace and Operator tries to issue/free any book which is requested via adding/deleting any BookIssueRequest.

How to Build

You can build it as any standard maven project

mvn clean install

Installing Custom Resource Definitions

As an administrator, you would need to create these CRDs in your Kubernetes cluster:

kubectl create -f src/main/resources/k8s/crds/book-crd.yaml
kubectl create -f src/main/resources/k8s/crds/bookissuerequest-crd.yaml

How to Run

Make sure that you have access to a Kubernetes Cluster(minikube or crc). You can start your Operator locally using standard Quarkus Maven Plugin goals:

mvn quarkus:dev

Deploying to Kubernetes using Eclipse JKube

In order to deploy this Operator to Kubernetes, we will be using Eclipse JKube. First we would need to deploy Role, RoleBinding and ServiceAccount for our Operator to Kubernetes

kubectl create -f src/main/resources/k8s/role.yaml
kubectl create -f src/main/resources/k8s/rolebinding.yaml
kubectl create -f src/main/resources/k8s/serviceaccount.yaml

Then you should be able to deploy the Operator using this command:

mvn k8s:deploy -PKubernetes

About

A Simple Kubernetes Operator following Library's Book issue/return mechanism using Quarkus Kubernetes Client Extension


Languages

Language:Java 67.0%Language:HTML 33.0%