Created
June 15, 2021 06:36
-
-
Save sandipchitale/0ef8f493c3d793caee8fd9fea3d3319f to your computer and use it in GitHub Desktop.
fabric8 java client #kubernetes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
plugins { | |
id 'java' | |
id 'application' | |
} | |
group = 'com.example' | |
version = '0.0.1-SNAPSHOT' | |
sourceCompatibility = '11' | |
repositories { | |
mavenCentral() | |
} | |
dependencies { | |
implementation 'io.fabric8:kubernetes-client:4.10.3' | |
} | |
test { | |
useJUnitPlatform() | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.jo; | |
import io.fabric8.kubernetes.client.Config; | |
import io.fabric8.kubernetes.client.ConfigBuilder; | |
import io.fabric8.kubernetes.client.DefaultKubernetesClient; | |
import io.fabric8.kubernetes.client.KubernetesClient; | |
import io.fabric8.kubernetes.client.KubernetesClientException; | |
public class JoApplication { | |
public static void main(String[] args) { | |
Config config = new ConfigBuilder().build(); | |
try (KubernetesClient client = new DefaultKubernetesClient(config)) { | |
client.pods().inAnyNamespace().list().getItems().forEach( | |
n -> System.out.println(n.getKind() + "\t" + n.getMetadata().getName() + "@" + n.getMetadata().getNamespace())); | |
} catch (KubernetesClientException ex) { | |
// Handle exception | |
ex.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment