在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):kubernetes-client/csharp开源软件地址(OpenSource Url):https://github.com/kubernetes-client/csharp开源编程语言(OpenSource Language):C# 100.0%开源软件介绍(OpenSource Introduction):Kubernetes C# ClientUsagedotnet add package KubernetesClient Authentication/ConfigurationYou should be able to use a standard KubeConfig file with this library,
see the You should also be able to authenticate with the in-cluster service
account using the MonitoringThere is optional built-in metric generation for prometheus client metrics. The exported metrics are:
There is an example integrating these monitors in the examples/prometheus directory. Sample CodeCreating 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 Objectsvar 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 Objectsvar 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()); ExamplesThere is extensive example code in the examples directory. Running the examplesgit clone [email protected]:kubernetes-client/csharp.git
cd csharp\examples\simple
dotnet run Known issuesWhile 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. TestingThe project uses XUnit as unit testing framework. To run the tests: cd csharp\tests
dotnet restore
dotnet test Update the API modelPrerequisitesYou'll need a Linux machine with Docker. Check out the generator project into some other directory
(henceforth 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
ContributingPlease see CONTRIBUTING.md for instructions on how to contribute. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论