KubeOps

Build Kubernetes Operators in .NET with Ease

.NET Pre-Release .NET Release Scheduled Code Security Testing

KubeOps is a Kubernetes Operator SDK designed for .NET developers. It allows you to leverage your C# skills and the rich .NET ecosystem to build powerful Kubernetes controllers that automate the management of complex applications. KubeOps simplifies operator development by providing high-level abstractions, code generators, and helper utilities.

For comprehensive documentation, tutorials, and API references, please visit the official KubeOps Documentation Site.

The documentation is also provided within the code itself (description of methods and classes), and each package contains a README with further information.

Key Features

  • Define CRDs in C#: Model your Custom Resource Definitions (CRDs) using plain C# classes and attributes.
  • Controller Logic: Implement reconciliation logic using the IResourceController<TEntity> interface.
  • Finalizers: Easily add cleanup logic before resource deletion with IResourceFinalizer<TEntity>.
  • Webhooks: Create Admission (validating/mutating) and Conversion webhooks integrated with ASP.NET Core.
  • Code Generation: Includes Roslyn source generators and a CLI tool (dotnet kubeops) to automate boilerplate code for CRDs, controllers, and RBAC rules.
  • Enhanced Kubernetes Client: Provides convenience methods built on top of the official client library.
  • Leader Election: Automatic handling for high-availability operator deployments.
  • Testing Support: Provides utilities and patterns to help with unit and integration testing.

Getting Started

The quickest way to start building an operator with KubeOps is by using the CLI tool:

  1. Install the CLI:

    dotnet tool install --global KubeOps.Cli
    

    (Or dotnet tool update --global KubeOps.Cli to get the latest version)

  2. Create a new operator project:

    dotnet kubeops new operator MyOperator
    cd MyOperator
    
  3. Explore the code: The template generates a basic operator structure with a sample custom resource, controller, and finalizer.

  4. Dive deeper: Follow the tutorials and guides on the KubeOps Documentation Site.

Packages

All packages target .NET 8.0 and .NET 9.0, leveraging modern C# features. The underlying Kubernetes client library (KubernetesClient.Official) also follows this versioning strategy.

The SDK is designed to be modular. You can include only the packages you need:

Package Description Latest Version
KubeOps.Abstractions Defines core interfaces, attributes (like [KubernetesEntity]), and base classes used across the SDK. Essential for defining your custom resources and controllers. Nuget
KubeOps.Cli A .NET Tool providing commands for scaffolding projects, generating Custom Resource Definitions (CRDs), and more. Nuget
KubeOps.Generator Contains Roslyn Source Generators to automate boilerplate code generation for CRDs and controllers based on your definitions. Nuget
KubeOps.KubernetesClient Provides an enhanced client for interacting with the Kubernetes API, built on top of the official KubernetesClient library. Offers convenience methods for common operator tasks. Nuget
KubeOps.Operator The main engine of the SDK. Handles reconciling resources, watching for changes, and managing the operator lifecycle. This is the primary package needed to run an operator. Nuget
KubeOps.Operator.Web Integrates the operator with ASP.NET Core to expose endpoints for features like Admission Webhooks. Nuget
KubeOps.Transpiler Utilities for converting .NET type definitions into Kubernetes YAML manifests, specifically for CRDs and RBAC rules. Nuget

Note: NuGet badges show the latest pre-release version.

Examples

You can find various example operators demonstrating different features in the examples/ directory of this repository.

Governance

KubeOps is currently maintained by [the original author/maintainer team - consider listing names or linking to GitHub profiles/team page]. We welcome community contributions and aim to foster an open and collaborative development process. As the project grows, we may establish a more formal governance structure. Decision-making primarily occurs through GitHub issues and pull requests.

Contribution

If you want to contribute, feel free to open a pull request or write issues :-) Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms. + Read more about contribution (especially for setting up your local environment) in the CONTRIBUTING file.

In short:

  • Check out the code
  • Develop on KubeOps
  • Use some Kubernetes to run the test operator against
  • Create tests
  • Build the whole solution (lint warnings will result in an error)
  • Open PR

Motivation

KubeOps aims to provide a first-class experience for developing Kubernetes operators within the .NET ecosystem, offering an alternative to Go-based SDKs like Kubebuilder and Operator SDK, while embracing familiar C# patterns and tooling.

Why choose KubeOps?

  • Leverage your .NET Skills: Build operators using C#, a language you already know, with access to the extensive .NET Base Class Library and NuGet ecosystem.
  • Strong Typing & IDE Support: Benefit from compile-time checks and rich IDE features like IntelliSense and debugging.
  • Simplified Abstractions: Focus on your reconciliation logic, not Kubernetes API boilerplate.
  • Code Generation: Reduce manual effort with generators for CRDs, RBAC, and controller/webhook registrations.
  • Integrated Testing: Develop unit and integration tests using familiar .NET testing frameworks.