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());
}