Files
csharp/examples/exec/Exec.cs
Boshi Lian 85755ccb3e 8.0: API Group + v1.24 (#850)
* swagger 1.24

* trim converter

* api group

* before moving method

* grouped api for client

* fix classic build

* fix e2e

* move all code to v8

* fix vis to

* bump ver

* fix authtest filename
2022-05-07 13:05:17 -07:00

38 lines
1.2 KiB
C#
Executable File

using System;
using System.Threading.Tasks;
using k8s;
using k8s.Models;
namespace exec
{
internal class Exec
{
private static async Task Main(string[] args)
{
var config = KubernetesClientConfiguration.BuildConfigFromConfigFile();
IKubernetes client = new Kubernetes(config);
Console.WriteLine("Starting Request!");
var list = client.CoreV1.ListNamespacedPod("default");
var pod = list.Items[0];
await ExecInPod(client, pod).ConfigureAwait(false);
}
private async static Task ExecInPod(IKubernetes client, V1Pod pod)
{
var webSocket =
await client.WebSocketNamespacedPodExecAsync(pod.Metadata.Name, "default", "ls",
pod.Spec.Containers[0].Name).ConfigureAwait(false);
var demux = new StreamDemuxer(webSocket);
demux.Start();
var buff = new byte[4096];
var stream = demux.GetStream(1, 1);
var read = stream.Read(buff, 0, 4096);
var str = System.Text.Encoding.Default.GetString(buff);
Console.WriteLine(str);
}
}
}