|
| 1 | +# Kubernetes Java Client |
| 2 | + |
1 | 3 | [](https://travis-ci.org/kubernetes-client/java) |
| 4 | +[](https://github.com/kubernetes/community/blob/master/contributors/design-proposals/csi-new-client-library-procedure.md#client-capabilities) |
| 5 | +[](https://github.com/kubernetes/community/blob/master/contributors/design-proposals/csi-new-client-library-procedure.md#client-support-level) |
| 6 | + |
| 7 | +Java client for the [kubernetes](http://kubernetes.io/) API. |
| 8 | + |
| 9 | +## Example |
| 10 | + |
| 11 | +list all pods: |
| 12 | + |
| 13 | +```java |
| 14 | +import io.kubernetes.client.ApiClient; |
| 15 | +import io.kubernetes.client.ApiException; |
| 16 | +import io.kubernetes.client.Configuration; |
| 17 | +import io.kubernetes.client.apis.CoreV1Api; |
| 18 | +import io.kubernetes.client.models.V1Pod; |
| 19 | +import io.kubernetes.client.models.V1PodList; |
| 20 | +import io.kubernetes.client.util.Config; |
| 21 | + |
| 22 | +import java.io.IOException; |
| 23 | + |
| 24 | +public class Example { |
| 25 | + public static void main(String[] args) throws IOException, ApiException{ |
| 26 | + ApiClient client = Config.defaultClient(); |
| 27 | + Configuration.setDefaultApiClient(client); |
| 28 | + |
| 29 | + CoreV1Api api = new CoreV1Api(); |
| 30 | + V1PodList list = api.listPodForAllNamespaces(null, null, null, null, null, null); |
| 31 | + for (V1Pod item : list.getItems()) { |
| 32 | + System.out.println(item.getMetadata().getName()); |
| 33 | + } |
| 34 | + } |
| 35 | +} |
| 36 | +``` |
| 37 | + |
| 38 | +watch on namespace object: |
| 39 | + |
| 40 | +```java |
| 41 | +import com.google.gson.reflect.TypeToken; |
| 42 | +import io.kubernetes.client.ApiClient; |
| 43 | +import io.kubernetes.client.Watch; |
| 44 | +import io.kubernetes.client.ApiException; |
| 45 | +import io.kubernetes.client.Configuration; |
| 46 | +import io.kubernetes.client.apis.CoreV1Api; |
| 47 | +import io.kubernetes.client.models.V1Namespace; |
| 48 | +import io.kubernetes.client.util.Config; |
| 49 | + |
| 50 | +import java.io.IOException; |
| 51 | + |
| 52 | +public class WatchExample { |
| 53 | + public static void main(String[] args) throws IOException, ApiException{ |
| 54 | + ApiClient client = Config.defaultClient(); |
| 55 | + Configuration.setDefaultApiClient(client); |
| 56 | + |
| 57 | + CoreV1Api api = new CoreV1Api(); |
| 58 | + |
| 59 | + Watch<V1Namespace> watch = client.watch( |
| 60 | + api.listNamespaceCall(null, null, null, null, 5, Boolean.TRUE, null, null), |
| 61 | + new TypeToken<Watch.Response<V1Namespace>>(){}.getType()); |
| 62 | + |
| 63 | + for (Watch.Response<V1Namespace> item : watch) { |
| 64 | + System.out.printf("%s : %s%n", item.type, item.object.getMetadata().getName()); |
| 65 | + } |
| 66 | + } |
| 67 | +} |
| 68 | +``` |
| 69 | + |
| 70 | +More examples can be found in [examples](examples/) folder. To run examples, run this command: |
| 71 | + |
| 72 | +```shell |
| 73 | +mvn exec:java -Dexec.mainClass="io.kubernetes.client.examples.Example" |
| 74 | +``` |
| 75 | + |
| 76 | +## Documentation |
| 77 | + |
| 78 | +All APIs and Models' documentation can be found at the [Generated client's README file](kubernetes/README.md) |
| 79 | + |
| 80 | +## Community, Support, Discussion |
| 81 | + |
| 82 | +You can reach the maintainers of this project at [SIG API Machinery](https://github.com/kubernetes/community/tree/master/sig-api-machinery). If you have any problem with the package or any suggestions, please file an [issue](https://github.com/kubernetes-client/java/issues). |
| 83 | + |
| 84 | +### Code of Conduct |
| 85 | + |
| 86 | +Participation in the Kubernetes community is governed by the [CNCF Code of Conduct](https://github.com/cncf/foundation/blob/master/code-of-conduct.md). |
2 | 87 |
|
3 | | -# java |
4 | | -Work In Progress |
| 88 | +# Development |
5 | 89 |
|
6 | | -# Update client |
| 90 | +## Update client |
7 | 91 |
|
8 | 92 | to update the client clone the `gen` repo and run this command at the root of the client repo: |
9 | 93 |
|
|
0 commit comments