dependabot[bot] cacda9e879 Bump Microsoft.NET.Test.Sdk from 17.6.2 to 17.6.3 (#1329)
Bumps [Microsoft.NET.Test.Sdk](https://github.com/microsoft/vstest) from 17.6.2 to 17.6.3.
- [Release notes](https://github.com/microsoft/vstest/releases)
- [Changelog](https://github.com/microsoft/vstest/blob/main/docs/releases.md)
- [Commits](https://github.com/microsoft/vstest/compare/v17.6.2...v17.6.3)

---
updated-dependencies:
- dependency-name: Microsoft.NET.Test.Sdk
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-07-09 03:05:04 -07:00
2023-05-03 02:58:12 -07:00
2022-12-05 08:55:04 -08:00
2023-06-20 13:14:21 -07:00
2021-09-14 11:20:05 -07:00
2018-08-19 15:46:42 -07:00
2023-04-23 14:01:13 -07:00
2022-12-15 18:21:36 -08:00
2021-04-23 18:49:14 -07:00
2022-03-21 19:19:44 -07:00
2021-04-08 07:56:57 -07:00
2022-12-15 18:21:36 -08:00
2018-06-25 07:14:27 -07:00
2023-04-23 14:01:13 -07:00
2023-04-23 14:01:13 -07:00

Kubernetes C# Client

Travis Client Capabilities Client Support Level

Usage

Nuget Package

dotnet add package KubernetesClient

Authentication/Configuration

You should be able to use a 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 with the in-cluster service account using the InClusterConfig function shown below.

Monitoring

There is optional built-in metric generation for prometheus client metrics. The exported metrics are:

  • k8s_dotnet_request_total - Counter of request, broken down by HTTP Method
  • k8s_dotnet_response_code_total - Counter of responses, broken down by HTTP Method and response code
  • k8s_request_latency_seconds - Latency histograms broken down by method, api group, api version and resource kind

There is an example integrating these monitors in the examples/prometheus directory.

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.CoreV1.ListNamespace();
foreach (var ns in namespaces.Items) {
    Console.WriteLine(ns.Metadata.Name);
    var list = client.CoreV1.ListNamespacedPod(ns.Metadata.Name);
    foreach (var item in list.Items)
    {
        Console.WriteLine(item.Metadata.Name);
    }
}

Creating and Deleting Objects

var ns = new V1Namespace
{
    Metadata = new V1ObjectMeta
    {
        Name = "test"
    }
};

var result = client.CoreV1.CreateNamespace(ns);
Console.WriteLine(result);

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

Examples

There is extensive example code in the examples directory.

Running the examples

git clone git@github.com:kubernetes-client/csharp.git
cd csharp\examples\simple
dotnet run

Known issues

While the 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. You can still connect to a cluster by starting the proxy command:

$ kubectl proxy
Starting to serve on 127.0.0.1:8001

and changing config:

var config = new KubernetesClientConfiguration {  Host = "http://127.0.0.1:8001" };

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

Testing

The project uses XUnit as unit testing framework.

To run the tests:

cd csharp\tests
dotnet restore
dotnet test

Update the API model

Prerequisites

You'll need a Linux machine with Docker.

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

cd $GEN_DIR/..
git clone https://github.com/kubernetes-client/gen

Generating new swagger.json

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

Version Compatibility

SDK Version Kubernetes Version .NET Targeting
10.0 1.26 net6.0;net7.0;net48*;netstandard2.0*
9.1 1.25 netstandard2.1;net6.0;net7.0;net48*;netstandard2.0*
9.0 1.25 netstandard2.1;net5.0;net6.0;net48*;netstandard2.0*
8.0 1.24 netstandard2.1;net5.0;net6.0;net48*;netstandard2.0*
7.2 1.23 netstandard2.1;net5.0;net6.0;net48*;netstandard2.0*
7.0 1.23 netstandard2.1;net5.0;net6.0
6.0 1.22 netstandard2.1;net5.0
5.0 1.21 netstandard2.1;net5
4.0 1.20 netstandard2.0;netstandard2.1
3.0 1.19 netstandard2.0;net452
2.0 1.18 netstandard2.0;net452
1.6 1.16 netstandard1.4;netstandard2.0;net452;
1.4 1.13 netstandard1.4;net451
1.3 1.12 netstandard1.4;net452
  • Starting from 2.0, dotnet sdk versioning adopted
  • Kubernetes Version here means the version sdk models and apis were generated from
  • Kubernetes api server guarantees the compatibility with n-2 version. for exmaple, 1.19 based sdk should work with 1.21 cluster, but no guarantee works with 1.22 cluster. see also https://kubernetes.io/releases/version-skew-policy/
  • * KubernetesClient.Classic: netstandard2.0 and net48 are supported with limited features

Contributing

Please see CONTRIBUTING.md for instructions on how to contribute.

Description
No description provided
Readme Apache-2.0 11 MiB
Languages
C# 100%