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:
- A basic operator implementation
- Maven configuration with required dependencies
- Generated CustomResourceDefinition (CRD)
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
- 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
- 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
- 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
Apply the CustomResourceDefinition:
kubectl apply -f target/classes/META-INF/fabric8/[resource-name]-v1.yml
Run the operator:
mvn exec:java -Dexec.mainClass="your.main.ClassName"
Or run your main class directly from your IDE.
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:
- MySQL Schema sample README
- Individual sample directories for specific setup requirements
Next Steps
After exploring the samples:
- Review the patterns and best practices guide
- Learn about implementing reconcilers
- Explore dependent resources and workflows for advanced use cases
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.