Skip to content

Commit 4046256

Browse files
Add a logs example. (#117)
1 parent d0c17ee commit 4046256

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

examples/logs/Logs.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System;
2+
using System.IO;
3+
using System.Threading.Tasks;
4+
using k8s;
5+
6+
namespace logs
7+
{
8+
internal class Logs
9+
{
10+
private static async Task Main(string[] args)
11+
{
12+
var config = KubernetesClientConfiguration.BuildConfigFromConfigFile();
13+
IKubernetes client = new Kubernetes(config);
14+
Console.WriteLine("Starting Request!");
15+
16+
var list = client.ListNamespacedPod("default");
17+
if (list.Items.Count == 0) {
18+
Console.WriteLine("No pods!");
19+
return;
20+
}
21+
var pod = list.Items[0];
22+
23+
var response = await client.ReadNamespacedPodLogWithHttpMessagesAsync(pod.Metadata.Name, pod.Metadata.NamespaceProperty, follow: true);
24+
var stream = response.Body;
25+
stream.CopyTo(Console.OpenStandardOutput());
26+
}
27+
}
28+
}

examples/logs/logs.csproj

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<ItemGroup>
4+
<ProjectReference Include="..\..\src\KubernetesClient.csproj" />
5+
</ItemGroup>
6+
7+
<PropertyGroup>
8+
<OutputType>Exe</OutputType>
9+
<TargetFramework>netcoreapp2.0</TargetFramework>
10+
<LangVersion>7.1</LangVersion>
11+
</PropertyGroup>
12+
13+
</Project>

0 commit comments

Comments
 (0)