Archetypical.Software.K8s.Utilities 2.0.0

dotnet add package Archetypical.Software.K8s.Utilities --version 2.0.0
                    
NuGet\Install-Package Archetypical.Software.K8s.Utilities -Version 2.0.0
                    
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="Archetypical.Software.K8s.Utilities" Version="2.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Archetypical.Software.K8s.Utilities" Version="2.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Archetypical.Software.K8s.Utilities" />
                    
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 Archetypical.Software.K8s.Utilities --version 2.0.0
                    
#r "nuget: Archetypical.Software.K8s.Utilities, 2.0.0"
                    
#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 Archetypical.Software.K8s.Utilities@2.0.0
                    
#: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=Archetypical.Software.K8s.Utilities&version=2.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Archetypical.Software.K8s.Utilities&version=2.0.0
                    
Install as a Cake Tool

Archetypical.Software.K8s.Utilities

Utilities extending the KubeOps and IKubernetes Client. This package provides:

  • Safe, helper-oriented CRUD patterns for IKubernetesClient
  • Pod exec helpers with timeout handling
  • Lightweight port-forwarding utilities (raw socket + HttpClient)

Compatibility

This package multi-targets .NET 8, 9, and 10. Package dependencies are pinned per target framework to prevent cross-framework version mismatches.

Target Framework KubeOps.KubernetesClient Microsoft.Extensions.Configuration
net8.0 8.0.0 8.0.0
net9.0 9.0.2 9.0.0
net10.0 10.0.4 10.0.0

Installation

dotnet add package Archetypical.Software.K8s.Utilities

Package contents

Extension methods for IKubernetesClient

DeleteProtected

Deletes a resource without throwing on 404. Returns a V1Status with the HTTP status code and message.

await client.DeleteProtected<MyCustomResource>("resource-name", "default");
UpdateStatusProtected

Updates the status subresource and optionally handles resource version conflicts by reloading the latest metadata.

await client.UpdateStatusProtected(resource, force: true);
Upsert

Creates or updates a resource depending on existence.

var saved = await client.Upsert(resource);

Pod execution

PodExecutor provides a serialized execution helper for NamespacedPodExecAsync with a configurable timeout.

var executor = new PodExecutor(configuration);
var output = await executor.ExecOnPod(client, pod, container, "ls", "-la");

Configuration key:

  • POD_EXECUTION_TIMEOUT_OVERRIDE (seconds, default: 30)

Port forwarding (raw socket)

K8SPortForward.ConnectAsync creates a local TCP listener that forwards to a pod port. This is intentionally single-threaded and intended for lightweight tooling.

using var forward = await K8SPortForward.ConnectAsync(k8sClient, pod, portOnPod: 8080, portOnMachine: 18080);

Port forwarding for HttpClient

K8SPortForwardedHttpClient.Create builds a wrapper around an HttpClient that forwards traffic to a pod using the port-forwarding websocket. The returned object implements IDisposable and should be disposed when no longer needed.

using var httpClient = await K8SPortForwardedHttpClient.Create(k8sClient, pod, new[] { 8080 });
var response = await httpClient.GetAsync("http://localhost/");

Testing

This repository includes an xUnit test project targeting .NET 8.

dotnet test

Build and pack

The package is configured to generate a NuGet package on build.

dotnet build -c Release

Troubleshooting

  • If port-forwarding appears to hang, ensure the pod and container are running and that network policies allow port-forwarding.
  • If UpdateStatusProtected conflicts, set force: true to reload the latest resource version before retrying.

License

GPL-3.0-only. See LICENSE.

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

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.0 98 2/15/2026
1.0.1 431 6/15/2024
1.0.0 181 5/29/2024