Writing Kubernetes Sample Controller in Java

Writing Kubernetes Sample Controller in Java

I recently saw this Sample Controller repository on kubernetes Github repository. This just implements a simple controller for watching CustomResource named Foo as defined within a CustomResourceDefinition.

I recently saw this Sample Controller repository on kubernetes Github repository. This just implements a simple controller for watching CustomResource named Foo as defined within a CustomResourceDefinition.

I thought it would be a good idea to port this example which is written in GoLang to Java using Fabric8 Kubernetes Client to get an idea of doing these operations but in Java:

  • How to register a new custom resource (custom resource type) of type Foo using a CustomResourceDefinition.
  • How to create/get/list instances of your new resource type Foo.
  • How to setup a controller on resource handling create/update/delete events.

What are we going to build?

If you’re not familiar with kubernetes/sample-controlleralready; let me give you some idea of what it does. We will be building a simple controller for a CustomResource Foo which looks like this:

Whenever a Fooresource gets created, it creates a child Deployment.Inside Foo CustomResource’s spec we specify the name with which we want the child Deployment to be created and the number of replicas this Deployment should have. When we delete the Foo resource, child Deployment should get deleted too.

Whenever there is a change in Foo resource’s Spec, child Deployment get updated accordingly.

controller java fabric8 kubernetes sample

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

50+ Useful Kubernetes Tools for 2020 - Part 2

Our original Kubernetes tool list was so popular that we've curated another great list of tools to help you improve your functionality with the platform.

How to Install OpenJDK 11 on CentOS 8

What is OpenJDK? OpenJDk or Open Java Development Kit is a free, open-source framework of the Java Platform, Standard Edition (or Java SE).

Handling Kubernetes Custom Resources in Java using Fabric8 Kubernetes Client

This blog is a continuation of my earlier blog regarding handling CustomResources in Java using Fabric8 Kubernetes Client API. You can find a link to part 1 of this blog here.

Difference between Fabric8 and Official Kubernetes Java Client

I’ve been approached by people a lot asking about how Fabric8 Kubernetes Client is different from official Kubernetes Client and why don’t we shift to official client instead for all our usages.

Mock Kubernetes API server in Java using Fabric8 Kubernetes Mock Server

In this blog, I would be giving you an overview of mocking and writing tests for you Kubernetes controllers using Fabric8 Kubernetes Mock Server. It’s a library based on Fabric8 Kubernetes Client and Fabric8 Mockwebserver(extension of OkHttp’s mockwebserver) which provides us smooth dsl for mocking operations.