KubeOps.KubernetesClient 10.2.3

dotnet add package KubeOps.KubernetesClient --version 10.2.3
                    
NuGet\Install-Package KubeOps.KubernetesClient -Version 10.2.3
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="KubeOps.KubernetesClient" Version="10.2.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="KubeOps.KubernetesClient" Version="10.2.3" />
                    
Directory.Packages.props
<PackageReference Include="KubeOps.KubernetesClient" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add KubeOps.KubernetesClient --version 10.2.3
                    
#r "nuget: KubeOps.KubernetesClient, 10.2.3"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package KubeOps.KubernetesClient@10.2.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=KubeOps.KubernetesClient&version=10.2.3
                    
Install as a Cake Addin
#tool nuget:?package=KubeOps.KubernetesClient&version=10.2.3
                    
Install as a Cake Tool

KubeOps Kubernetes Client

NuGet NuGet Pre-Release

This package provides an enhanced, developer-friendly interface for interacting with the Kubernetes API, built on top of the official kubernetes-client/csharp library. While the official client is powerful, it often requires verbose calls, especially for Custom Resources.

The KubeOps.KubernetesClient simplifies common operator tasks by offering:

  • True Generic Methods: Perform operations like Get, List, Create, Update, Delete, and Watch on any Kubernetes resource type (including custom resources defined with [KubernetesEntity]) using strongly-typed generic methods, without manually specifying API group, version, and plural name.
  • Simplified API: Reduces boilerplate code for common CRUD operations.
  • Type Safety: Leverages C# generics for better compile-time checking.

This is an enhanced version of the original Google Kubernetes Client. It extends the original client with additional features, such as true generics and method variants. The original GenericClient supports generics in a limited way, requiring initialization with group and kind information.

The client acts as a wrapper, automatically handling the complexities of determining the correct API endpoint and resource mapping based on the provided C# type.

Usage

When using the main KubeOps.Operator package, an instance of IKubernetesClient is automatically registered in the .NET Dependency Injection container. You can inject it into your controllers, finalizers, or webhooks:

using KubeOps.KubernetesClient;
using KubeOps.Operator.Controller;
using MyOperator.Entities; // Your custom entity
using k8s.Models; // For built-in types like V1Pod

public class MyResourceController : IResourceController<V1MyResource>
{
    private readonly IKubernetesClient _client;

    public MyResourceController(IKubernetesClient client)
    {
        _client = client;
    }

    public async Task<ResourceControllerResult?> ReconcileAsync(V1MyResource entity)
    {
        // Use the client to interact with the cluster
        var pod = await _client.GetAsync<V1Pod>("my-pod", entity.Namespace());
        if (pod == null)
        {
            var newPod = new V1Pod { /* ... */ };
            await _client.CreateAsync(newPod);
        }

        // Get a custom resource
        var otherResource = await _client.GetAsync<V1OtherResource>("other-resource-name", entity.Namespace());

        return null; // Requeue later
    }
}

Standalone Usage

If you need to use the client outside the main KubeOps operator framework (e.g., in a command-line tool or script), you can instantiate it directly. The client automatically loads configuration based on standard Kubernetes conventions (Kubeconfig file or in-cluster service account).

using KubeOps.KubernetesClient;
using k8s.Models;

// Instantiate the client
IKubernetesClient client = new KubernetesClient();

// List all namespaces
var namespaces = await client.ListAsync<V1Namespace>();
foreach (var ns in namespaces)
{
    Console.WriteLine($"Namespace: {ns.Name()}");
}

// Get a specific ConfigMap
var configMap = await client.GetAsync<V1ConfigMap>("my-config", "default");
if (configMap != null)
{
    Console.WriteLine($"ConfigMap Data: {string.Join(',', configMap.Data)}");
}

For advanced configuration (e.g., custom Kubeconfig paths, timeouts), refer to the underlying k8s.KubernetesClientConfiguration documentation from the official client library.

Examples

List Resources

var client = new KubernetesClient() as IKubernetesClient;

// Get all namespaces in the cluster
var namespaces = await client.ListAsync<V1Namespace>();

// List all pods in the 'staging' namespace
var podsInStaging = await client.ListAsync<V1Pod>("staging");

// List all custom resources of type V1MyCrd across all namespaces
// Note: This requires appropriate RBAC permissions for cluster-scoped resources
var allMyCrds = await client.ListAsync<V1MyCrd>(null);

Get Resources

// Get a Pod in the 'production' namespace
var pod = await client.GetAsync<V1Pod>("my-app-pod-xyz", "production");

// Get a custom resource
var myCrd = await client.GetAsync<V1MyCrd>("my-instance", "default");

Create Resources

var newConfigMap = new V1ConfigMap
{
    Metadata = new V1ObjectMeta { Name = "new-map", NamespaceProperty = "default" },
    Data = new Dictionary<string, string> { { "key", "value" } }
};
var createdMap = await client.CreateAsync(newConfigMap);

Update Resources

var existingPod = await client.GetAsync<V1Pod>("my-pod", "default");
if (existingPod != null)
{
    existingPod.Metadata.Annotations ??= new Dictionary<string, string>();
    existingPod.Metadata.Annotations["my-annotation"] = "updated-value";
    var updatedPod = await client.UpdateAsync(existingPod);
}

Update Resource Status

// Update the status of a custom resource
var existingCrd = await client.GetAsync<V1MyCrd>("my-instance", "default");
if (existingCrd != null)
{
    existingCrd.Status.Message = "Processing completed";
    var updatedCrd = await client.UpdateStatusAsync(existingCrd);
}

Watch Resources

// Watch for Pod events in the 'default' namespace
await foreach (var (type, pod) in client.WatchAsync<V1Pod>(namespaceParameter: "default"))
{
    Console.WriteLine($"Event: {type}, Pod: {pod.Name()}");
    // Handle Added, Modified, Deleted events
}

Delete Resources

// Delete by name and namespace
await client.DeleteAsync<V1Pod>("pod-to-delete", "default");

// Delete using an existing resource instance
var crdToDelete = await client.GetAsync<V1MyCrd>("crd-instance-to-delete", "dev");
if (crdToDelete != null)
{
    await client.DeleteAsync(crdToDelete);
}
Product 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 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (4)

Showing the top 4 NuGet packages that depend on KubeOps.KubernetesClient:

Package Downloads
KubeOps

This is an operator sdk written in c#. It enables a developer to create a custom controller for CRDs (CustomResourceDefinitions) that runs on kubernetes.

KubeOps.Operator

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 may run without ASP.net but needs the IHost of dotnet to run.

KubernetesClient.Extensions.Configuration

Package Description

Archetypical.Software.K8s.Utilities

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
10.2.3 631 2/4/2026
10.2.3-prerelease.1 34 2/4/2026
10.2.2 159 2/3/2026
10.2.2-prerelease.1 50 1/30/2026
10.2.1 1,787 1/20/2026
10.2.1-prerelease.1 80 1/14/2026
10.2.0 592 1/13/2026
10.2.0-prerelease.2 55 1/9/2026
10.2.0-prerelease.1 53 1/9/2026
10.1.0 851 1/6/2026
10.1.0-prerelease.1 55 1/2/2026
10.0.5-prerelease.2 54 1/2/2026
10.0.5-prerelease.1 53 1/1/2026
10.0.4 617 12/23/2025
10.0.4-prerelease.2 133 12/22/2025
10.0.4-prerelease.1 234 12/17/2025
10.0.3 1,158 12/16/2025
10.0.3-prerelease.2 179 12/14/2025
10.0.3-prerelease.1 402 12/10/2025
10.0.2 1,298 12/9/2025
10.0.2-prerelease.1 167 12/3/2025
10.0.1 1,467 12/2/2025
10.0.1-prerelease.1 151 11/27/2025
10.0.0 714 11/25/2025
10.0.0-prerelease.4 183 11/25/2025
10.0.0-prerelease.3 218 11/24/2025
10.0.0-prerelease.2 170 11/24/2025
10.0.0-prerelease.1 385 11/21/2025
9.11.10-prerelease.1 250 11/13/2025
9.11.9 9,806 11/11/2025
9.11.9-prerelease.1 124 11/7/2025
9.11.8 5,271 10/28/2025
9.11.8-prerelease.1 151 10/26/2025
9.11.7 2,633 10/15/2025
9.11.7-prerelease.2 146 10/15/2025
9.11.7-prerelease.1 145 10/14/2025
9.11.6 340 10/14/2025
9.11.6-prerelease.1 91 10/10/2025
9.11.5 686 10/7/2025
9.11.5-prerelease.2 142 10/5/2025
9.11.5-prerelease.1 168 10/1/2025
9.11.4 6,420 9/16/2025
9.11.4-prerelease.1 154 9/10/2025
9.11.3 1,611 9/9/2025
9.11.3-prerelease.1 141 9/7/2025
9.11.2 3,176 8/19/2025
9.11.2-prerelease.2 143 8/17/2025
9.11.2-prerelease.1 174 8/12/2025
9.11.1 3,845 7/29/2025
9.11.1-prerelease.3 167 7/27/2025
9.11.1-prerelease.2 496 7/24/2025
9.11.1-prerelease.1 543 7/22/2025
9.11.0 4,528 7/22/2025
9.11.0-prerelease.7 160 7/17/2025
9.11.0-prerelease.6 149 7/17/2025
9.11.0-prerelease.5 140 7/17/2025
9.11.0-prerelease.4 152 7/17/2025
9.11.0-prerelease.3 152 7/17/2025
9.11.0-prerelease.2 143 7/16/2025
9.11.0-prerelease.1 145 7/16/2025
9.10.0 3,385 7/3/2025
9.9.0 979 6/30/2025
9.8.2 1,510 6/20/2025
9.8.1 1,128 6/13/2025
9.8.0 899 6/10/2025
9.7.0 792 6/6/2025
9.6.0 15,020 5/23/2025
9.5.0 7,090 5/8/2025
9.4.1 12,334 4/29/2025
9.4.0 444 4/28/2025
9.3.0 41,288 3/26/2025
9.2.0 14,183 1/24/2025
9.1.5 52,534 9/10/2024
9.1.4 1,776 8/26/2024
9.1.3 24,640 6/28/2024
9.1.2 11,707 6/20/2024
9.1.1 6,510 5/22/2024
9.1.0 3,225 5/15/2024
9.0.2 880 5/13/2024
9.0.0 30,075 3/13/2024
9.0.0-pre.4 127 4/19/2024
9.0.0-pre.3 122 3/21/2024
9.0.0-pre.2 140 3/13/2024
9.0.0-pre.1 161 3/7/2024
8.0.2-pre.2 136 2/21/2024
8.0.2-pre.1 132 2/19/2024
8.0.1 12,973 2/13/2024
8.0.1-pre.7 146 2/12/2024
8.0.1-pre.6 131 2/7/2024
8.0.1-pre.5 140 2/5/2024
8.0.1-pre.4 140 1/31/2024
8.0.1-pre.3 122 1/26/2024
8.0.1-pre.2 151 1/25/2024
8.0.1-pre.1 155 1/18/2024
8.0.0 1,291 1/17/2024
8.0.0-pre.45 136 1/17/2024
8.0.0-pre.44 152 1/16/2024
8.0.0-pre.43 104 1/16/2024
8.0.0-pre.42 1,035 1/10/2024
8.0.0-pre.41 358 1/2/2024
8.0.0-pre.40 261 12/27/2023
8.0.0-pre.39 143 12/21/2023
8.0.0-pre.38 498 12/6/2023
8.0.0-pre.37 171 12/6/2023
8.0.0-pre.36 201 12/3/2023
8.0.0-pre.35 173 11/28/2023
8.0.0-pre.34 150 11/24/2023
8.0.0-pre.33 154 11/24/2023
8.0.0-pre.32 136 11/23/2023
8.0.0-pre.31 142 11/23/2023
8.0.0-pre.30 166 11/23/2023
8.0.0-pre.29 1,027 11/11/2023
8.0.0-pre.28 175 11/8/2023
8.0.0-pre.27 658 10/23/2023
8.0.0-pre.26 169 10/19/2023
8.0.0-pre.25 155 10/18/2023
8.0.0-pre.24 161 10/13/2023
8.0.0-pre.23 154 10/13/2023
8.0.0-pre.22 149 10/13/2023
8.0.0-pre.21 139 10/12/2023
8.0.0-pre.20 164 10/11/2023
8.0.0-pre.19 156 10/9/2023
8.0.0-pre.18 145 10/9/2023
8.0.0-pre.17 145 10/7/2023
8.0.0-pre.16 189 10/6/2023
8.0.0-pre.15 155 10/6/2023
8.0.0-pre.14 132 10/5/2023
8.0.0-pre.13 113 10/5/2023
8.0.0-pre.12 153 10/4/2023
8.0.0-pre.11 134 10/3/2023
8.0.0-pre.10 120 10/3/2023
8.0.0-pre.9 134 10/3/2023
8.0.0-pre.8 141 10/2/2023
8.0.0-pre.7 146 10/2/2023
8.0.0-pre.6 165 9/29/2023
7.6.1 64,147 9/29/2023
7.6.0 3,185 9/19/2023
7.5.0 1,001 9/13/2023
7.4.5 564 9/13/2023
7.4.4 7,121 8/28/2023
7.4.3 540 8/28/2023
7.4.2 5,207 7/17/2023
7.4.1 658 7/17/2023
7.4.0 18,648 6/26/2023
7.3.0 1,560 6/1/2023
7.2.0 10,025 4/14/2023
7.1.2 826 4/14/2023
7.1.1 7,098 3/1/2023
7.1.0 777 3/1/2023
7.0.10 863 2/27/2023
7.0.9 878 2/23/2023
7.0.8 811 2/23/2023
7.0.7 1,020 2/14/2023
7.0.6 1,398 2/6/2023
7.0.5 1,016 2/3/2023
7.0.4 930 1/30/2023
7.0.3 867 1/30/2023
7.0.2 1,142 1/26/2023
7.0.1 1,260 1/23/2023 7.0.1 is deprecated because it has critical bugs.
7.0.0 1,050 1/19/2023 7.0.0 is deprecated because it has critical bugs.