|
10 | 10 | dotnet add package KubernetesClient
|
11 | 11 | ```
|
12 | 12 |
|
13 |
| -# Generating the Client Code |
| 13 | +# Usage |
14 | 14 |
|
15 |
| -## Prerequisites |
| 15 | +## Authentication/Configuration |
| 16 | +You should be able to use an standard KubeConfig file with this library, |
| 17 | +see the `BuildConfigFromConfigFile` function below. Most authentication |
| 18 | +methods are currently supported, but a few are not, see the |
| 19 | +[known-issues](https://github.com/kubernetes-client/csharp#known-issues) |
16 | 20 |
|
17 |
| -You'll need a Linux machine with Docker. |
| 21 | +You should also be able to authenticate using the in-cluster service |
| 22 | +account using the `InClusterConfig` function shown below. |
18 | 23 |
|
19 |
| -The generated code works on all platforms supported by .NET or .NET Core. |
| 24 | +## Sample Code |
20 | 25 |
|
21 |
| -Check out the generator project into some other directory |
22 |
| -(henceforth `$GEN_DIR`) |
| 26 | +### Creating the client |
| 27 | +```c# |
| 28 | +// Load from the default kubeconfig on the machine. |
| 29 | +var config = KubernetesClientConfiguration.BuildConfigFromConfigFile(); |
23 | 30 |
|
24 |
| -```bash |
25 |
| -cd $GEN_DIR/.. |
26 |
| -git clone https://github.com/kubernetes-client/gen |
| 31 | +// Load from a specific file: |
| 32 | +var config = KubernetesClientConfiguration.BuildConfigFromConfigFile(Environment.GetEnvironmentVariable("KUBECONFIG")); |
| 33 | + |
| 34 | +// Load from in-cluster configuration: |
| 35 | +var config = KubernetesClientConfiguration.InClusterConfig() |
| 36 | + |
| 37 | +// Use the config object to create a client. |
| 38 | +var client = new Kubernetes(config); |
27 | 39 | ```
|
28 | 40 |
|
29 |
| -## Generating code |
| 41 | +### Listing Objects |
| 42 | +```c# |
| 43 | +var namespaces = client.ListNamespace(); |
| 44 | +foreach (var ns in namespaces.Items) { |
| 45 | + Console.WriteLine(ns.Metadata.Name); |
| 46 | + var list = client.ListNamespacedPod(ns.Metadata.Name); |
| 47 | + foreach (var item in list.Items) |
| 48 | + { |
| 49 | + Console.WriteLine(item.Metadata.Name); |
| 50 | + } |
| 51 | +} |
| 52 | +``` |
30 | 53 |
|
31 |
| -```bash |
32 |
| -# Where REPO_DIR points to the root of the csharp repository |
33 |
| -cd ${REPO_DIR}/csharp/src/KubernetesClient |
34 |
| -${GEN_DIR}/openapi/csharp.sh generated ../csharp.settings |
| 54 | +### Creating and Deleting Objects |
| 55 | +```c# |
| 56 | +var ns = new V1Namespace |
| 57 | +{ |
| 58 | + Metadata = new V1ObjectMeta |
| 59 | + { |
| 60 | + Name = "test" |
| 61 | + } |
| 62 | +}; |
| 63 | + |
| 64 | +var result = client.CreateNamespace(ns); |
| 65 | +Console.WriteLine(result); |
| 66 | + |
| 67 | +var status = client.DeleteNamespace(ns.Metadata.Name, new V1DeleteOptions()); |
35 | 68 | ```
|
36 | 69 |
|
37 |
| -# Usage |
| 70 | +## Examples |
| 71 | + |
| 72 | +There is extensive example code in the [examples directory](https://github.com/kubernetes-client/csharp/tree/master/examples). |
38 | 73 |
|
39 |
| -## Running the Examples |
| 74 | +### Running the Examples |
40 | 75 |
|
41 | 76 | ```bash
|
42 | 77 | git clone [email protected]:kubernetes-client/csharp.git
|
@@ -80,6 +115,30 @@ dotnet restore
|
80 | 115 | dotnet test
|
81 | 116 | ```
|
82 | 117 |
|
| 118 | +# Generating the Client Code |
| 119 | + |
| 120 | +## Prerequisites |
| 121 | + |
| 122 | +You'll need a Linux machine with Docker. |
| 123 | + |
| 124 | +The generated code works on all platforms supported by .NET or .NET Core. |
| 125 | + |
| 126 | +Check out the generator project into some other directory |
| 127 | +(henceforth `$GEN_DIR`) |
| 128 | + |
| 129 | +```bash |
| 130 | +cd $GEN_DIR/.. |
| 131 | +git clone https://github.com/kubernetes-client/gen |
| 132 | +``` |
| 133 | + |
| 134 | +## Generating code |
| 135 | + |
| 136 | +```bash |
| 137 | +# Where REPO_DIR points to the root of the csharp repository |
| 138 | +cd ${REPO_DIR}/csharp/src/KubernetesClient |
| 139 | +${GEN_DIR}/openapi/csharp.sh generated ../csharp.settings |
| 140 | +``` |
| 141 | + |
83 | 142 | ## Contributing
|
84 | 143 |
|
85 | 144 | Please see [CONTRIBUTING.md](CONTRIBUTING.md) for instructions on how to contribute.
|
0 commit comments