Giter VIP home page Giter VIP logo

kubernetes.dotnet's Introduction

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

kubernetes.dotnet's People

Contributors

masroorhasan avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.