Skip to content
Kubernetes C# client for .NET Framework
Branch: master
Clone or download
masroorhasan update travis deploy script (#20)
* travis deploy from script

* update readme
Latest commit 578e3d8 Oct 9, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.swagger-codegen Fixes for build, packing and optimize auto-gen (#8) Nov 26, 2017
docs Fixes for build, packing and optimize auto-gen (#8) Nov 26, 2017
scripts Switch to Travis CI (#13) Nov 29, 2017
src add namespace to kubecfg context data (#19) Oct 4, 2018
swagger Fixes for build, packing and optimize auto-gen (#8) Nov 26, 2017
.gitignore Fixes for build, packing and optimize auto-gen (#8) Nov 26, 2017
.swagger-codegen-ignore Fixes for build, packing and optimize auto-gen (#8) Nov 26, 2017
.travis.yml update travis deploy script (#20) Oct 9, 2018
Kubernetes.DotNet.sln Fixes for build, packing and optimize auto-gen (#8) Nov 26, 2017
LICENSE Initial commit Oct 21, 2017
README.md update travis deploy script (#20) Oct 9, 2018
build.bat Build and deploy package (#10) Nov 26, 2017
deploy.sh

README.md

Kubernetes.DotNet

Build Status

The C# client SDK for Kubernetes API spec on .NET 4.5+ platform.

Usage

Create client using kube config

Create a client instance using configuration parsed from %USERPROFILE%\.kube\config with specified authentication type.

// Initialize client with default kube config using SSL authentication
IKubernetesClient k8sClient = new KubeConfigClientConfiguration().CreateClient(AuthType.SSLAuth);

Create a client using custom path to kubeconfig file.

string configPath = "path\\to\\kube\\config";
IKubernetesClient k8sClient = new KubeConfigClientConfiguration(configPath).CreateClient(AuthType.SSLAuth);

Create client using custom config

Create a client instance by extending IClientConfiguration for custom configuration and authentication type.

// Initialize client with user provided SSL configuration
IKubernetesClient k8sClient = new SslClientConfiguration
{
    ClusterUri = new Uri("https://your-k8s-cluster.cloudapp.azure.com"),
    Certificate = new X509Certificate2("path\\to\\cert.pfx", "password")
}.CreateClient();

List all Pods in Namespace

V1PodList podList = k8sClient.CoreApi.ListNamespacedPod("default");
foreach (V1Pod pod in podList.Items)
    Console.WriteLine($"Pod name={pod.Metadata.Name}, object={pod.ToString()}");

Create a Pod in Namespace

k8sClient.CoreApi.CreateNamespacedPod(
    "default",
    new V1Pod(
        Metadata: new V1ObjectMeta(Name: "iis-example"),
        Spec: new V1PodSpec(
            Containers: new List<V1Container>
            {
                new V1Container(
                    Image: "microsoft/iis:nanoserver",
                    Name: "iis",
                    Ports: new List<V1ContainerPort> { new V1ContainerPort(ContainerPort: 80) })
            })
        )
    );

Development

Generate C# client using docker container. Image definition in scripts/Dockerfile.

Dependencies

  • BouncyCastle
  • Newtonsoft.Json
  • RestSharp
  • YamlDotNet

Build image

docker build -t k8s-client-gen .
  • K8S_BRANCH_VERSION: Kubernetes API version, i.e. "release-1.7".
  • GEN_OP_TYPE: Type of code gen operation, i.e. "create" or "update".

Generate project from empty state

docker run -e "K8S_BRANCH_VERSION=release-1.7" -e "GEN_OP_TYPE=create" -v /path/to/code/root/:/usr/src/app/gen/ k8s-client-gen

Update generated API spec only

docker run -e "K8S_BRANCH_VERSION=release-1.7" -e "GEN_OP_TYPE=update" -v /path/to/code/root/:/usr/src/app/gen/ k8s-client-gen
You can’t perform that action at this time.