Java client for the kubernetes API.
To install the Java client library to your local Maven repository, simply execute:
git clone --recursive https://github.com/kubernetes-client/java
cd java
mvn install
Refer to the official documentation for more information.
Add this dependency to your project's POM:
<dependency>
<groupId>io.kubernetes</groupId>
<artifactId>client-java</artifactId>
<version>1.0.0</version>
<scope>compile</scope>
</dependency>
compile 'io.kubernetes:client-java:1.0.0'
At first generate the JAR by executing:
git clone --recursive https://github.com/kubernetes-client/java
cd java
mvn package
Then manually install the following JARs:
- target/client-java-1.0.0-SNAPSHOT.jar
- target/lib/*.jar
list all pods:
import io.kubernetes.client.ApiClient;
import io.kubernetes.client.ApiException;
import io.kubernetes.client.Configuration;
import io.kubernetes.client.apis.CoreV1Api;
import io.kubernetes.client.models.V1Pod;
import io.kubernetes.client.models.V1PodList;
import io.kubernetes.client.util.Config;
import java.io.IOException;
public class Example {
public static void main(String[] args) throws IOException, ApiException{
ApiClient client = Config.defaultClient();
Configuration.setDefaultApiClient(client);
CoreV1Api api = new CoreV1Api();
V1PodList list = api.listPodForAllNamespaces(null, null, null, null, null, null, null, null, null);
for (V1Pod item : list.getItems()) {
System.out.println(item.getMetadata().getName());
}
}
}
watch on namespace object:
import com.google.gson.reflect.TypeToken;
import io.kubernetes.client.ApiClient;
import io.kubernetes.client.ApiException;
import io.kubernetes.client.Configuration;
import io.kubernetes.client.apis.CoreV1Api;
import io.kubernetes.client.models.V1Namespace;
import io.kubernetes.client.util.Config;
import io.kubernetes.client.util.Watch;
import java.io.IOException;
public class WatchExample {
public static void main(String[] args) throws IOException, ApiException{
ApiClient client = Config.defaultClient();
Configuration.setDefaultApiClient(client);
CoreV1Api api = new CoreV1Api();
Watch<V1Namespace> watch = Watch.createWatch(
client,
api.listNamespaceCall(null, null, null, null, null, 5, null, null, Boolean.TRUE, null, null),
new TypeToken<Watch.Response<V1Namespace>>(){}.getType());
for (Watch.Response<V1Namespace> item : watch) {
System.out.printf("%s : %s%n", item.type, item.object.getMetadata().getName());
}
}
}
More examples can be found in examples folder. To run examples, run this command:
mvn exec:java -Dexec.mainClass="io.kubernetes.client.examples.Example"
All APIs and Models' documentation can be found at the Generated client's README file
Kubernetes 1.4 | Kubernetes 1.5 | Kubernetes 1.6 | Kubernetes 1.7 | Kubernetes 1.8 | Kubernetes 1.9 | |
---|---|---|---|---|---|---|
java-client 0.1.0 | + | + | ✓ | - | - | - |
java-client 0.2.0 | + | + | ✓ | - | - | - |
java-client 1.0.0-beta1 | + | + | + | + | ✓ | - |
java-client 1.0.0-beta2 | + | + | + | + | ✓ | - |
java-client 1.0.0-beta3 | + | + | + | + | ✓ | - |
java-client 1.0.0-beta4 | + | + | + | + | ✓ | - |
java-client 1.0.0 | + | + | + | + | ✓ | - |
Key:
✓
Exactly the same features / API objects in both java-client and the Kubernetes version.+
java-client has features or api objects that may not be present in the Kubernetes cluster, but everything they have in common will work.-
The Kubernetes cluster has features the java-client library can't use (additional API objects, etc).
See the CHANGELOG for a detailed description of changes between java-client versions.
You can reach the maintainers of this project at SIG API Machinery. If you have any problem with the package or any suggestions, please file an issue.
Participation in the Kubernetes community is governed by the CNCF Code of Conduct.
to update the client clone the gen
repo and run this command at the root of the client repo:
${GEN_REPO_BASE}/openapi/java.sh kubernetes settings