How to use the Kubernetes C# client library

Take advantage of the official .NET Kubernetes client and .NET or .NET Core to build your own Kubernetes tools

How to use the Kubernetes C# client library
TU-KA / Getty Images

Working with Kubernetes isn’t always easy. Managing your clusters and pods requires work, and although cloud-hosted Kubernetes instances such as Azure’s AKS can handle much of the heavy lifting for you, they’re not available if you’re running Kubernetes on-premises or on your own virtual infrastructures.

That’s where Kubernetes’ API comes in to play, as it’s how Kubernetes communicates between components and external controllers. You can use the kubectl command line tools to communicate with the API or use it through familiar REST (Representational State Transfer) calls. The API helps you manage workloads, configure clusters, and manage the behavior of your applications and cluster.

RESTful APIs like this are useful tools, but they require significant development work if you’re building your own controllers. You can remove the associated development overhead by working through one of the official Kubernetes API clients, which now include a .NET library. In addition to the official versions, there are unofficial clients, which include two alternative .NET implementations if the official release doesn’t quite fit with how you want to use it.

Introducing the .NET Kubernetes API client library

The official .NET client library is available on GitHub, managed by a team of open source developers that includes Microsoft staff. The current release is 1.6.21, and development is ongoing. You can download the code from GitHub and compile it yourself or add the library to an application via NuGet as a package called KubernetesClient. Once installed, add the library to your code with a using statement that loads the client, as k8s. The library supports both .NET and .NET Core, so you can use it to write cross-platform apps as well as purely Windows code.

To continue reading this article register now