Skip to content
Work In Progress
Branch: master
Clone or download
tg123 and k8s-ci-robot gen v1.16.0 (#312)
* gen v1.16.0

* update version.json
Latest commit 8ab95b6 Oct 2, 2019

Kubernetes C# Client

Travis Client Capabilities Client Support Level


Nuget Package

dotnet add package KubernetesClient


You should be able to use an standard KubeConfig file with this library, see the BuildConfigFromConfigFile function below. Most authentication methods are currently supported, but a few are not, see the known-issues

You should also be able to authenticate using the in-cluster service account using the InClusterConfig function shown below.

Sample Code

Creating the client

// Load from the default kubeconfig on the machine.
var config = KubernetesClientConfiguration.BuildConfigFromConfigFile();

// Load from a specific file:
var config = KubernetesClientConfiguration.BuildConfigFromConfigFile(Environment.GetEnvironmentVariable("KUBECONFIG"));

// Load from in-cluster configuration:
var config = KubernetesClientConfiguration.InClusterConfig()

// Use the config object to create a client.
var client = new Kubernetes(config);

Listing Objects

var namespaces = client.ListNamespace();
foreach (var ns in namespaces.Items) {
    var list = client.ListNamespacedPod(ns.Metadata.Name);
    foreach (var item in list.Items)

Creating and Deleting Objects

var ns = new V1Namespace
    Metadata = new V1ObjectMeta
        Name = "test"

var result = client.CreateNamespace(ns);

var status = client.DeleteNamespace(ns.Metadata.Name, new V1DeleteOptions());


There is extensive example code in the examples directory.

Running the Examples

git clone
cd csharp\examples\simple
dotnet run

Known issues

While preferred way of connecting to a remote cluster from local machine is:

var config = KubernetesClientConfiguration.BuildConfigFromConfigFile();
var client = new Kubernetes(config);

Not all auth providers are supported at moment #91, but you still can connect to cluster by starting proxy:

$ kubectl proxy
Starting to serve on

and changing config:

var config = new KubernetesClientConfiguration {  Host = "" };

Notice that this is a workaround and is not recommended for production use


The project uses XUnit as unit testing framework.

To run the tests

cd csharp\tests
dotnet restore
dotnet test

Generating the Client Code


You'll need a Linux machine with Docker.

The generated code works on all platforms supported by .NET or .NET Core.

Check out the generator project into some other directory (henceforth $GEN_DIR)

cd $GEN_DIR/..
git clone

Generating code

# Where REPO_DIR points to the root of the csharp repository
cd ${REPO_DIR}/csharp/src/KubernetesClient
${GEN_DIR}/openapi/ generated ../csharp.settings


Please see for instructions on how to contribute.

You can’t perform that action at this time.