[BAEL-4782] Initial import (#10513)

* [BAEL-4782] Initial import

* [BAEL-4782] LiveTest & Readme

* [BAEL-4782] spacing issues
This commit is contained in:
psevestre
2021-03-08 12:45:37 -03:00
committed by GitHub
parent fc5d08d3f6
commit ce6f1e878e
6 changed files with 103 additions and 1 deletions
+13
View File
@@ -0,0 +1,13 @@
# Kubernetes Java API Sample Code
This module contains sample code used to show how to use the Kubernetes client Java API.
Before running those samples, make sure that your environment is correctly configured to access
a working Kubernetes cluster.
An easy way to check that everything is working as expected is issuing any *kubectl get* command:
```shell
$ kubectl get nodes
```
If you get a valid response, then you're good to go.
+35
View File
@@ -0,0 +1,35 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.baeldung</groupId>
<artifactId>kubernetes-parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>k8s-intro</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>io.kubernetes</groupId>
<artifactId>client-java</artifactId>
<version>11.0.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<!-- http://maven.apache.org/plugins/maven-compiler-plugin/ -->
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
@@ -0,0 +1,31 @@
/**
*
*/
package com.baeldung.kubernetes.intro;
import io.kubernetes.client.openapi.ApiClient;
import io.kubernetes.client.openapi.apis.CoreV1Api;
import io.kubernetes.client.openapi.models.V1NodeList;
import io.kubernetes.client.util.Config;
/**
* @author Philippe
*
*/
public class ListNodes {
/**
* @param args
*/
public static void main(String[] args) throws Exception {
ApiClient client = Config.defaultClient();
CoreV1Api api = new CoreV1Api(client);
V1NodeList nodeList = api.listNode(null, null, null, null, null, null, null, null, 10, false);
nodeList.getItems()
.stream()
.forEach((node) -> System.out.println(node.getMetadata()));
}
}
@@ -0,0 +1,10 @@
package com.baeldung.kubernetes.intro;
import org.junit.jupiter.api.Test;
class ListNodesLiveTest {
@Test
void whenListNodes_thenSuccess() throws Exception {
ListNodes.main(new String[] {});
}
}
+13
View File
@@ -0,0 +1,13 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-modules</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>kubernetes-parent</artifactId>
<packaging>pom</packaging>
<modules>
<module>k8s-intro</module>
</modules>
</project>
+1 -1
View File
@@ -471,7 +471,7 @@
<module>json-path</module>
<module>jsoup</module>
<module>jta</module>
<module>kubernetes</module>
<!-- <module>lagom</module> --> <!-- Not a maven project -->
<module>language-interop</module>
<module>libraries-2</module>