-
Notifications
You must be signed in to change notification settings - Fork 292
/
Exec.cs
executable file
·37 lines (32 loc) · 1.16 KB
/
Exec.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using k8s;
using k8s.Models;
using System;
using System.Threading.Tasks;
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 static async 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);
}
}
}