KubeOps.Operator
9.8.0
dotnet add package KubeOps.Operator --version 9.8.0
NuGet\Install-Package KubeOps.Operator -Version 9.8.0
<PackageReference Include="KubeOps.Operator" Version="9.8.0" />
<PackageVersion Include="KubeOps.Operator" Version="9.8.0" />
<PackageReference Include="KubeOps.Operator" />
paket add KubeOps.Operator --version 9.8.0
#r "nuget: KubeOps.Operator, 9.8.0"
#addin nuget:?package=KubeOps.Operator&version=9.8.0
#tool nuget:?package=KubeOps.Operator&version=9.8.0
KubeOps Operator
The KubeOps.Operator
package provides a framework for building Kubernetes operators in .NET. Built on top of the Kubernetes client libraries for .NET, it offers abstractions and utilities for implementing operators that manage custom resources in a Kubernetes cluster.
Getting Started
Install the package from NuGet:
dotnet add package KubeOps.Operator
After installation, you can create entities, controllers, finalizers, and other components to implement your operator.
All resources must be registered with the operator builder to be recognized by the SDK and used as operator resources. The KubeOps.Generator
provides convenience methods to register all components at once.
You'll need to use the Generic Host to run your operator. For a plain operator without webhooks, ASP.NET is not required (unlike v7).
using KubeOps.Operator;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
var builder = Host.CreateApplicationBuilder(args);
builder.Logging.SetMinimumLevel(LogLevel.Trace);
builder.Services
.AddKubernetesOperator()
.RegisterComponents();
using var host = builder.Build();
await host.RunAsync();
Registering Resources
When using the KubeOps.Generator, you can use the RegisterComponents
function:
builder.Services
.AddKubernetesOperator()
.RegisterComponents();
Alternatively, you can register resources manually:
builder.Services
.AddKubernetesOperator()
.AddController<TestController, V1TestEntity>()
.AddFinalizer<FirstFinalizer, V1TestEntity>("first")
.AddFinalizer<SecondFinalizer, V1TestEntity>("second");
Entity
To create an entity, implement the IKubernetesObject<V1ObjectMeta>
interface. The SDK provides convenience classes to help with initialization, status, and spec properties.
[KubernetesEntity(Group = "testing.dev", ApiVersion = "v1", Kind = "TestEntity")]
public class V1TestEntity :
CustomKubernetesEntity<V1TestEntity.EntitySpec, V1TestEntity.EntityStatus>
{
public override string ToString()
=> $"Test Entity ({Metadata.Name}): {Spec.Username} ({Spec.Email})";
public class EntitySpec
{
public string Username { get; set; } = string.Empty;
public string Email { get; set; } = string.Empty;
}
public class EntityStatus
{
public string Status { get; set; } = string.Empty;
}
}
Controller
A controller reconciles a specific entity type. Implement controllers using the IEntityController<TEntity>
interface. You can reconcile custom entities or other Kubernetes resources as long as they are registered with the operator. For guidance on reconciling external resources, refer to the documentation.
Example controller implementation:
using KubeOps.Abstractions.Controller;
using KubeOps.Abstractions.Rbac;
using KubeOps.KubernetesClient;
using Microsoft.Extensions.Logging;
[EntityRbac(typeof(V1TestEntity), Verbs = RbacVerb.All)]
public class V1TestEntityController : IEntityController<V1TestEntity>
{
private readonly IKubernetesClient _client;
private readonly EntityFinalizerAttacher<FinalizerOne, V1TestEntity> _finalizer1;
private readonly ILogger<V1TestEntityController> _logger;
public V1TestEntityController(
IKubernetesClient client,
EntityFinalizerAttacher<FinalizerOne, V1TestEntity> finalizer1,
ILogger<V1TestEntityController> logger)
{
_client = client;
_finalizer1 = finalizer1;
_logger = logger;
}
public async Task ReconcileAsync(V1TestEntity entity, CancellationToken cancellationToken)
{
_logger.LogInformation("Reconciling entity {Entity}.", entity);
// Attach finalizer and get updated entity
entity = await _finalizer1(entity);
// Update status to indicate reconciliation in progress
entity.Status.Status = "Reconciling";
entity = await _client.UpdateStatus(entity);
// Update status to indicate reconciliation complete
entity.Status.Status = "Reconciled";
await _client.UpdateStatus(entity);
}
public Task DeletedAsync(V1TestEntity entity, CancellationToken cancellationToken)
{
_logger.LogInformation("Entity {Entity} deleted.", entity);
return Task.CompletedTask;
}
}
This controller:
- Attaches a finalizer to the entity
- Updates the entity's status to indicate reconciliation is in progress
- Updates the status again to indicate reconciliation is complete
- Implements the required
DeletedAsync
method for handling deletion events
CAUTION: Always use the returned values from modifying actions of the Kubernetes client. Failure to do so will result in "HTTP CONFLICT" errors due to the resource version field in the entity.
NOTE: Do not update the entity itself in the reconcile loop. It is considered bad practice to update entities while reconciling them. However, the status may be updated. To update entities before they are reconciled (e.g., to validate or transform values), use webhooks instead.
Finalizer
A finalizer is a mechanism for asynchronous cleanup in Kubernetes. Implement finalizers using the IEntityFinalizer<TEntity>
interface.
Finalizers are attached using an EntityFinalizerAttacher
and are called when the entity is marked for deletion.
using KubeOps.Abstractions.Finalizer;
public class FinalizerOne : IEntityFinalizer<V1TestEntity>
{
public Task FinalizeAsync(V1TestEntity entity, CancellationToken cancellationToken)
{
// Implement cleanup logic here
return Task.CompletedTask;
}
}
NOTE: The controller's
DeletedAsync
method will be called after all finalizers are removed.
Documentation
For more information, visit the documentation.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- KubeOps.Abstractions (>= 9.8.0)
- KubeOps.KubernetesClient (>= 9.8.0)
- KubeOps.Transpiler (>= 9.8.0)
- Microsoft.Extensions.Hosting (>= 9.0.5)
-
net9.0
- KubeOps.Abstractions (>= 9.8.0)
- KubeOps.KubernetesClient (>= 9.8.0)
- KubeOps.Transpiler (>= 9.8.0)
- Microsoft.Extensions.Hosting (>= 9.0.5)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on KubeOps.Operator:
Package | Downloads |
---|---|
KubeOps.Operator.Web
This is an operator sdk written in c#. It enables a developer to create a custom controller for CRDs (CustomResourceDefinitions) that runs on kubernetes. This operator uses ASP.net to support webhooks and external access to the operator. |
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on KubeOps.Operator:
Repository | Stars |
---|---|
josephnhtam/live-streaming-server-net
A .NET implementation of RTMP live streaming server, supporting HTTP-FLV, WebSocket-FLV, HLS, Kubernetes, cloud storage services integration and more.
|
Version | Downloads | Last updated |
---|---|---|
9.8.0 | 0 | 6/10/2025 |
9.7.0 | 204 | 6/6/2025 |
9.6.0 | 1,564 | 5/23/2025 |
9.5.0 | 1,795 | 5/8/2025 |
9.4.1 | 2,043 | 4/29/2025 |
9.4.0 | 312 | 4/28/2025 |
9.3.0 | 4,189 | 3/26/2025 |
9.2.0 | 10,992 | 1/24/2025 |
9.1.5 | 37,659 | 9/10/2024 |
9.1.4 | 1,447 | 8/26/2024 |
9.1.3 | 17,652 | 6/28/2024 |
9.1.2 | 11,554 | 6/20/2024 |
9.1.1 | 5,368 | 5/22/2024 |
9.1.0 | 2,181 | 5/15/2024 |
9.0.2 | 271 | 5/13/2024 |
9.0.0 | 14,873 | 3/13/2024 |
9.0.0-pre.4 | 87 | 4/19/2024 |
9.0.0-pre.3 | 76 | 3/21/2024 |
9.0.0-pre.2 | 75 | 3/13/2024 |
9.0.0-pre.1 | 82 | 3/7/2024 |
8.0.2-pre.2 | 93 | 2/21/2024 |
8.0.2-pre.1 | 76 | 2/19/2024 |
8.0.1 | 10,555 | 2/13/2024 |
8.0.1-pre.7 | 87 | 2/12/2024 |
8.0.1-pre.6 | 88 | 2/7/2024 |
8.0.1-pre.5 | 80 | 2/5/2024 |
8.0.1-pre.4 | 81 | 1/31/2024 |
8.0.1-pre.3 | 81 | 1/26/2024 |
8.0.1-pre.2 | 82 | 1/25/2024 |
8.0.1-pre.1 | 75 | 1/18/2024 |
8.0.0 | 933 | 1/17/2024 |
8.0.0-pre.45 | 74 | 1/17/2024 |
8.0.0-pre.44 | 77 | 1/16/2024 |
8.0.0-pre.43 | 75 | 1/16/2024 |
8.0.0-pre.42 | 824 | 1/10/2024 |
8.0.0-pre.41 | 309 | 1/2/2024 |
8.0.0-pre.40 | 178 | 12/27/2023 |
8.0.0-pre.39 | 92 | 12/21/2023 |
8.0.0-pre.38 | 430 | 12/6/2023 |
8.0.0-pre.37 | 149 | 12/6/2023 |
8.0.0-pre.36 | 152 | 12/3/2023 |
8.0.0-pre.35 | 113 | 11/28/2023 |
8.0.0-pre.34 | 105 | 11/24/2023 |
8.0.0-pre.33 | 82 | 11/24/2023 |
8.0.0-pre.32 | 81 | 11/23/2023 |
8.0.0-pre.31 | 88 | 11/23/2023 |
8.0.0-pre.30 | 88 | 11/23/2023 |
8.0.0-pre.29 | 493 | 11/11/2023 |
8.0.0-pre.28 | 102 | 11/8/2023 |
8.0.0-pre.27 | 592 | 10/23/2023 |
8.0.0-pre.26 | 123 | 10/19/2023 |
8.0.0-pre.25 | 91 | 10/18/2023 |
8.0.0-pre.24 | 112 | 10/13/2023 |
8.0.0-pre.23 | 92 | 10/13/2023 |
8.0.0-pre.22 | 88 | 10/13/2023 |
8.0.0-pre.21 | 94 | 10/12/2023 |
8.0.0-pre.20 | 98 | 10/11/2023 |
8.0.0-pre.19 | 94 | 10/9/2023 |
8.0.0-pre.18 | 90 | 10/9/2023 |
8.0.0-pre.17 | 86 | 10/7/2023 |
8.0.0-pre.16 | 120 | 10/6/2023 |
8.0.0-pre.15 | 87 | 10/6/2023 |
8.0.0-pre.14 | 86 | 10/5/2023 |
8.0.0-pre.13 | 84 | 10/5/2023 |
8.0.0-pre.12 | 87 | 10/4/2023 |
8.0.0-pre.11 | 88 | 10/3/2023 |
8.0.0-pre.10 | 94 | 10/3/2023 |
8.0.0-pre.9 | 87 | 10/3/2023 |
8.0.0-pre.8 | 86 | 10/2/2023 |
8.0.0-pre.7 | 86 | 10/2/2023 |
8.0.0-pre.6 | 88 | 9/29/2023 |
8.0.0-pre.5 | 83 | 9/28/2023 |
8.0.0-pre.4 | 83 | 9/28/2023 |
8.0.0-pre.3 | 93 | 9/27/2023 |
8.0.0-pre.2 | 72 | 9/26/2023 |
8.0.0-pre.1 | 82 | 9/22/2023 |
'# [9.8.0](https://github.com/buehler/dotnet-operator-sdk/compare/v9.7.0...v9.8.0) (2025-06-10)
### Bug Fixes
* **deps:** update dependency sonaranalyzer.csharp to 10.11.0.117924 ([#896](https://github.com/buehler/dotnet-operator-sdk/issues/896)) ([9896d8f](https://github.com/buehler/dotnet-operator-sdk/commit/9896d8f92c679ca1cec74e256c70fdd85f561c83))
* **deps:** update docusaurus monorepo to v3.8.1 ([#899](https://github.com/buehler/dotnet-operator-sdk/issues/899)) ([acd2ad0](https://github.com/buehler/dotnet-operator-sdk/commit/acd2ad0746c0f5456ede3b65d9b4b483ac9ff6dd))
### Features
* integrate `ActivitySource` for improved observability in resource watchers and operator builder ([#895](https://github.com/buehler/dotnet-operator-sdk/issues/895)) ([467dffd](https://github.com/buehler/dotnet-operator-sdk/commit/467dffd8f1a8c7bb4cf48f259fa5e73437f3783a))
'