Improve README.md with better example and descriptions. (#250)
* Improve README.md with better example and descriptions. * Address comments.
This commit is contained in:
committed by
Kubernetes Prow Robot
parent
8eb33b3de7
commit
bf995e55c6
109
README.md
109
README.md
@@ -10,33 +10,68 @@
|
|||||||
dotnet add package KubernetesClient
|
dotnet add package KubernetesClient
|
||||||
```
|
```
|
||||||
|
|
||||||
# Generating the Client Code
|
|
||||||
|
|
||||||
## Prerequisites
|
|
||||||
|
|
||||||
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`)
|
|
||||||
|
|
||||||
```bash
|
|
||||||
cd $GEN_DIR/..
|
|
||||||
git clone https://github.com/kubernetes-client/gen
|
|
||||||
```
|
|
||||||
|
|
||||||
## Generating code
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# Where REPO_DIR points to the root of the csharp repository
|
|
||||||
cd ${REPO_DIR}/csharp/src/KubernetesClient
|
|
||||||
${GEN_DIR}/openapi/csharp.sh generated ../csharp.settings
|
|
||||||
```
|
|
||||||
|
|
||||||
# Usage
|
# Usage
|
||||||
|
|
||||||
## Running the Examples
|
## Authentication/Configuration
|
||||||
|
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](https://github.com/kubernetes-client/csharp#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
|
||||||
|
```c#
|
||||||
|
// 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
|
||||||
|
```c#
|
||||||
|
var namespaces = client.ListNamespace();
|
||||||
|
foreach (var ns in namespaces.Items) {
|
||||||
|
Console.WriteLine(ns.Metadata.Name);
|
||||||
|
var list = client.ListNamespacedPod(ns.Metadata.Name);
|
||||||
|
foreach (var item in list.Items)
|
||||||
|
{
|
||||||
|
Console.WriteLine(item.Metadata.Name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Creating and Deleting Objects
|
||||||
|
```c#
|
||||||
|
var ns = new V1Namespace
|
||||||
|
{
|
||||||
|
Metadata = new V1ObjectMeta
|
||||||
|
{
|
||||||
|
Name = "test"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var result = client.CreateNamespace(ns);
|
||||||
|
Console.WriteLine(result);
|
||||||
|
|
||||||
|
var status = client.DeleteNamespace(ns.Metadata.Name, new V1DeleteOptions());
|
||||||
|
```
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
There is extensive example code in the [examples directory](https://github.com/kubernetes-client/csharp/tree/master/examples).
|
||||||
|
|
||||||
|
### Running the Examples
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
git clone git@github.com:kubernetes-client/csharp.git
|
git clone git@github.com:kubernetes-client/csharp.git
|
||||||
@@ -80,6 +115,30 @@ dotnet restore
|
|||||||
dotnet test
|
dotnet test
|
||||||
```
|
```
|
||||||
|
|
||||||
|
# Generating the Client Code
|
||||||
|
|
||||||
|
## Prerequisites
|
||||||
|
|
||||||
|
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`)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd $GEN_DIR/..
|
||||||
|
git clone https://github.com/kubernetes-client/gen
|
||||||
|
```
|
||||||
|
|
||||||
|
## Generating code
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Where REPO_DIR points to the root of the csharp repository
|
||||||
|
cd ${REPO_DIR}/csharp/src/KubernetesClient
|
||||||
|
${GEN_DIR}/openapi/csharp.sh generated ../csharp.settings
|
||||||
|
```
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
Please see [CONTRIBUTING.md](CONTRIBUTING.md) for instructions on how to contribute.
|
Please see [CONTRIBUTING.md](CONTRIBUTING.md) for instructions on how to contribute.
|
||||||
|
|||||||
Reference in New Issue
Block a user