Kubernetes API with .NET

Do stuff in your clusters directly from your app

Profile pictureToni Petrina
Published on 2023-11-271 min read
  • #dotnet
  • #kubernetes

A straightforward and simple library named KubernetesClient allows .NET applications to manipulate Kubernetes cluster.

First step: obtain the config. This can be done either with:

// Local development
var config = KubernetesClientConfiguration.BuildConfigFromConfigFile();

// Or after deployed in a cluster
var config = KubernetesClientConfiguration.InClusterConfig();

Then, create a new client instance:

var client = new Kubernetes(config);

Finally, let's list available namespaces:

var namespaces = client.CoreV1.ListNamespace();
foreach (var namespace in namespaces)
{
    Console.WriteLine(namespace.Name());
}

Change code theme: