Files
csharp/examples/customResource
Bliamoh 2d8915dff7 Update customResource example + bump nuget packages versions (#720)
Update customResource example nuget packages + update example

Update httpClientFactory example nuget packages

Update nuget packages

Change DateTime to DateTimeOffset

Update tests nuget packages

Make KubernetesClient project reference instead of Nuget package reference

Co-authored-by: Boshi Lian <farmer1992@gmail.com>

Co-authored-by: Boshi Lian <farmer1992@gmail.com>
2021-10-14 09:02:51 -07:00
..
2020-12-19 08:26:25 -08:00
2020-12-19 08:26:25 -08:00

Custom Resource Client Example

This example demonstrates how to use the C# Kubernetes Client library to create, get and list custom resources.

Pre-requisits

Make sure your have added the library package

dotnet add package KubernetesClient

Create Custom Resource Definition (CRD)

Make sure the CRD is created, in order to create an instance of it after.

kubectl create -f ./crd.yaml

You can test that the CRD is successfully added, by creating an instance of it using kubectl:

kubectl create -f ./config/yaml-cr-instance.yaml
kubectl get customresources.csharp.com

Execute the code

The client uses the BuildConfigFromConfigFile() function. If the KUBECONFIG environment variable is set, then that path to the k8s config file will be used.

dotnet run

Expected output:

strating main()...
working with CRD: customresources.csharp.com
creating CR cr-instance-london
CR list:
- CR Item 0 = cr-instance-london
- CR Item 1 = cr-instance-paris
fetchedCR = cr-instance-london (Labels: {identifier : city, newKey : newValue}), Spec: London
Deleted the CR

Under the hood

For more details, you can look at the Generic client implementation