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
<PackageReference Include="Archetypical.Software.K8s.Utilities" Version="2.0.0" />
<PackageVersion Include="Archetypical.Software.K8s.Utilities" Version="2.0.0" />
<PackageReference Include="Archetypical.Software.K8s.Utilities" />
paket add Archetypical.Software.K8s.Utilities --version 2.0.0
#r "nuget: Archetypical.Software.K8s.Utilities, 2.0.0"
#:package Archetypical.Software.K8s.Utilities@2.0.0
#addin nuget:?package=Archetypical.Software.K8s.Utilities&version=2.0.0
#tool nuget:?package=Archetypical.Software.K8s.Utilities&version=2.0.0
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
UpdateStatusProtectedconflicts, setforce: trueto reload the latest resource version before retrying.
License
GPL-3.0-only. See LICENSE.
| 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 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. |
-
net10.0
- KubeOps.KubernetesClient (>= 10.0.4)
- Microsoft.Extensions.Configuration (>= 10.0.0)
-
net8.0
- KubeOps.KubernetesClient (>= 8.0.0)
- Microsoft.Extensions.Configuration (>= 8.0.0)
-
net9.0
- KubeOps.KubernetesClient (>= 9.0.2)
- Microsoft.Extensions.Configuration (>= 9.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.