File tree Expand file tree Collapse file tree 2 files changed +56
-0
lines changed Expand file tree Collapse file tree 2 files changed +56
-0
lines changed Original file line number Diff line number Diff line change
1
+ using System ;
2
+ using System . Collections . Generic ;
3
+ using k8s ;
4
+
5
+ namespace simple
6
+ {
7
+ internal class PodList
8
+ {
9
+ private static void Main ( string [ ] args )
10
+ {
11
+ var config = KubernetesClientConfiguration . BuildConfigFromConfigFile ( ) ;
12
+ IKubernetes client = new Kubernetes ( config ) ;
13
+ Console . WriteLine ( "Starting Request!" ) ;
14
+
15
+ var list = client . ListNamespacedService ( "default" ) ;
16
+ foreach ( var item in list . Items )
17
+ {
18
+ Console . WriteLine ( "Pods for service: " + item . Metadata . Name ) ;
19
+ Console . WriteLine ( "=-=-=-=-=-=-=-=-=-=-=" ) ;
20
+ if ( item . Spec == null || item . Spec . Selector == null )
21
+ {
22
+ continue ;
23
+ }
24
+ var labels = new List < string > ( ) ;
25
+ foreach ( var key in item . Spec . Selector )
26
+ {
27
+ labels . Add ( key . Key + "=" + key . Value ) ;
28
+ }
29
+ var labelStr = string . Join ( "," , labels . ToArray ( ) ) ;
30
+ Console . WriteLine ( labelStr ) ;
31
+ var podList = client . ListNamespacedPod ( "default" , labelSelector : labelStr ) ;
32
+ foreach ( var pod in podList . Items )
33
+ {
34
+ Console . WriteLine ( pod . Metadata . Name ) ;
35
+ }
36
+ if ( podList . Items . Count == 0 )
37
+ {
38
+ Console . WriteLine ( "Empty!" ) ;
39
+ }
40
+ Console . WriteLine ( ) ;
41
+ }
42
+ }
43
+ }
44
+ }
Original file line number Diff line number Diff line change
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
+ </PropertyGroup >
11
+
12
+ </Project >
You can’t perform that action at this time.
0 commit comments