Bootstrapping and samples

Creating a New Operator Project

Using the Maven Plugin

The simplest way to start a new operator project is using the provided Maven plugin, which generates a complete project skeleton:

mvn io.javaoperatorsdk:bootstrapper:[version]:create \
  -DprojectGroupId=org.acme \
  -DprojectArtifactId=getting-started

This command creates a new Maven project with:

Building Your Project

Build the generated project with Maven:

mvn clean install

The build process automatically generates the CustomResourceDefinition YAML file that you’ll need to apply to your Kubernetes cluster.

Exploring Sample Operators

The sample-operators directory contains real-world examples demonstrating different JOSDK features and patterns:

Available Samples

webpage

  • Purpose: Creates NGINX webservers from Custom Resources containing HTML code
  • Key Features: Multiple implementation approaches using both low-level APIs and higher-level abstractions
  • Good for: Understanding basic operator concepts and API usage patterns

mysql-schema

  • Purpose: Manages database schemas in MySQL instances
  • Key Features: Demonstrates managing non-Kubernetes resources (external systems)
  • Good for: Learning how to integrate with external services and manage state outside Kubernetes

tomcat

  • Purpose: Manages Tomcat instances and web applications
  • Key Features: Multiple controllers managing related custom resources
  • Good for: Understanding complex operators with multiple resource types and relationships

Running the Samples

Prerequisites

The easiest way to try samples is using a local Kubernetes cluster:

Step-by-Step Instructions

  1. Apply the CustomResourceDefinition:

    kubectl apply -f target/classes/META-INF/fabric8/[resource-name]-v1.yml
    
  2. Run the operator:

    mvn exec:java -Dexec.mainClass="your.main.ClassName"
    

    Or run your main class directly from your IDE.

  3. Create custom resources: The operator will automatically detect and reconcile custom resources when you create them:

    kubectl apply -f examples/sample-resource.yaml
    

Detailed Examples

For comprehensive setup instructions and examples, see:

Next Steps

After exploring the samples:

  1. Review the patterns and best practices guide
  2. Learn about implementing reconcilers
  3. Explore dependent resources and workflows for advanced use cases

Last modified September 1, 2025: docs: wording improvements (#2913) (feec0012)