Git Product home page Git Product 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

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

kubernetes.dotnet's Issues

DotNet general protection ip regularly Kubernetes

I been experinecing an issue on kubernetes 1.10.3 running a dotnet application. In dmesg that comes with the core right before the containers crash this is this in the logs:
[11085.488191] traps: dotnet[25507] general protection ip:7ff4fbdf7529 sp:7fffc1dcec30 error:0 in libc-2.24.so[7ff4fbdc3000+195000]
[11089.047591] traps: dotnet[25686] general protection ip:7f9b2abd5529 sp:7ffcd05dad50 error:0 in libc-2.24.so[7f9b2aba1000+195000]
[11105.793408] traps: dotnet[25968] general protection ip:7fba1b462529 sp:7ffedfa79d00 error:0 in libc-2.24.so[7fba1b42e000+195000]
[11135.857805] traps: dotnet[26332] general protection ip:7fb697600529 sp:7ffe3f358aa0 error:0 in libc-2.24.so[7fb6975cc000+195000]
[11192.790916] traps: dotnet[27056] general protection ip:7f7bcf300529 sp:7ffe9ebc2f60 error:0 in libc-2.24.so[7f7bcf2cc000+195000]
[11286.072392] traps: dotnet[28148] general protection ip:7ffa5585a529 sp:7fffe0022ba0 error:0 in libc-2.24.so[7ffa55826000+195000]
[11410.006211] cbr0: port 16(vethd38bbb18) entered disabled state
[11410.015121] device vethd38bbb18 left promiscuous mode
[11410.015126] cbr0: port 16(vethd38bbb18) entered disabled state
[11449.848218] traps: dotnet[29897] general protection ip:7fedffa3a529 sp:7ffc68eb8690 error:0 in libc-2.24.so[7fedffa06000+195000]
[11765.713298] traps: dotnet[677] general protection ip:7f4e1d45d529 sp:7ffcc67081c0 erro
[292414.521699] dotnet D 0 15114 32343 0x00000000
[292414.521703] Call Trace:
[292414.521713] __schedule+0x3d6/0x8b0
[292414.521716] schedule+0x36/0x80
[292414.521718] rwsem_down_read_failed+0x10a/0x170
[292414.521722] ? __handle_mm_fault+0xd3c/0x11e0
[292414.521724] call_rwsem_down_read_failed+0x18/0x30
[292414.521726] ? call_rwsem_down_read_failed+0x18/0x30
[292414.521727] down_read+0x20/0x40
[292414.521731] __do_page_fault+0x465/0x500
[292414.521734] ? SyS_futex+0x7f/0x180
[292414.521736] do_page_fault+0x2e/0xf0
[292414.521738] ? page_fault+0x2f/0x50
[292414.521740] page_fault+0x45/0x50
[292414.521742] RIP: 0033:0x7fecd51f8485
[292414.521743] RSP: 002b:00007fecd31b84c0 EFLAGS: 00010206
[292414.521745] RAX: 00007fec439d20f8 RBX: 0000000000000001 RCX: 00007fec439d20c8
[292414.521745] RDX: 0000000000000010 RSI: 0000000000000020 RDI: 00007fecd31b8580
[292414.521746] RBP: 00007fecd31b8600 R08: 0000000000000000 R09: 00007fecd31b9400
[292414.521747] R10: 00007fec5bf0d168 R11: 000000000000000d R12: 0000000000000002
[292414.521748] R13: 00007fec5b7ae750 R14: 00007fec5ce4f160 R15: 0000000000000000
[292414.521750] NMI backtrace for cpu 0
[292414.521753] CPU: 0 PID: 17 Comm: khungtaskd Not tainted 4.15.0-1025-azure #2616.04.1-Ubuntu
[292414.521754] Hardware name: Microsoft Corporation Virtual Machine/Virtual Machine, BIOS 090007 06/02/2017
[292414.521754] Call Trace:
[292414.521759] dump_stack+0x63/0x82
[292414.521761] nmi_cpu_backtrace+0xcb/0xd0
[292414.521765] ? irq_force_complete_move+0x90/0x90
[292414.521767] nmi_trigger_cpumask_backtrace+0xef/0x140
[292414.521769] arch_trigger_cpumask_backtrace+0x19/0x20
[292414.521771] watchdog+0x2bf/0x340
[292414.521776] kthread+0x105/0x140
[292414.521778] ? reset_hung_task_detector+0x20/0x20
[292414.521780] ? kthread_destroy_worker+0x50/0x50
[292414.521781] ret_from_fork+0x35/0x40
[292414.521784] Kernel panic - not syncing: hung_task: blocked tasks
[292414.525625] CPU: 0 PID: 17 Comm: khungtaskd Not tainted 4.15.0-1025-azure #2616.04.1-Ubuntu
the version of libc is 2.24. Would this be more related to code or a problem with libc?

Error: "Property 'namespace' not found on type 'Kubernetes.DotNet.Config.ContextData'."

Hello,
I am trying to follow your more basic example. Getting configuration from .kube\config (on a Windows 10 OS).

But I always get this error:
"Property 'namespace' not found on type 'Kubernetes.DotNet.Config.ContextData'."

Anyway all my 'kubectl' commands run fine againts my selected/default namespace.

I think it is a problem of my own, but I cannot find it out how to avoid it on the startup guide.
Any idea?
Thanks.

Kubernetes.DotNet.Client.ApiException: Error calling ListNamespacedPod: The request was aborted: Could not create SSL/TLS secure channel.

I cannot get this to work using the code below and I'm wondering if anyone could help me. The contents of the filePath file is a copy & paste of the contents of my own ...\.kube\config file.

var k8Client = new KubeConfigClientConfiguration(filePath).CreateClient(AuthType.SSLAuth);
var podsList = k8Client.CoreApi.ListNamespacedPod("default");

The exception call stack is:

Kubernetes.DotNet.Client.ApiException: Error calling ListNamespacedPod: The request was aborted: Could not create SSL/TLS secure channel.
   at Kubernetes.DotNet.Api.Core_v1Api.ListNamespacedPodWithHttpInfo(String _namespace, String pretty, String fieldSelector, Nullable`1 includeUninitialized, String labelSelector, String resourceVersion, Nullable`1 timeoutSeconds, Nullable`1 watch)
   at Kubernetes.DotNet.Api.Core_v1Api.ListNamespacedPod(String _namespace, String pretty, String fieldSelector, Nullable`1 includeUninitialized, String labelSelector, String resourceVersion, Nullable`1 timeoutSeconds, Nullable`1 watch)
   at ScaleoutService.ScaleoutService._GetCurrentInstancesCount() in C:\Users\edaroczy\OneDrive - BoldIQ, Inc\Documents\projects\NetJets\ScaleoutService\ScaleoutService.IScaleoutService.cs:line 229

I'm making this call to an Azure Kubernetes Service instance from a .Net 4.5.2 microservice running within Service Fabric.

The assemblies that I'm using are:

  <package id="BouncyCastle" version="1.8.5" targetFramework="net452" />
  <package id="Kubernetes.DotNet" version="1.0.62" targetFramework="net452" />
  <package id="Newtonsoft.Json" version="10.0.1" targetFramework="net452" />
  <package id="RestSharp" version="105.1.0" targetFramework="net452" />
  <package id="YamlDotNet" version="4.2.2" targetFramework="net452" />

Support for .NET Standard

swagger-codegen for C# supports dotnet standard 1.3. Support the standard 1.3 platform on separate branch.

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.