@@ -61,65 +61,43 @@ Then manually install the following JARs:
61
61
62
62
## Example
63
63
64
- list all pods:
65
-
66
- ``` java
67
- import io.kubernetes.client.ApiClient ;
68
- import io.kubernetes.client.ApiException ;
69
- import io.kubernetes.client.Configuration ;
70
- import io.kubernetes.client.apis.CoreV1Api ;
71
- import io.kubernetes.client.models.V1Pod ;
72
- import io.kubernetes.client.models.V1PodList ;
73
- import io.kubernetes.client.util.Config ;
74
-
75
- import java.io.IOException ;
76
-
77
- public class Example {
78
- public static void main (String [] args ) throws IOException , ApiException {
79
- ApiClient client = Config . defaultClient();
80
- Configuration . setDefaultApiClient(client);
81
-
82
- CoreV1Api api = new CoreV1Api ();
83
- V1PodList list = api. listPodForAllNamespaces(null , null , null , null , null , null , null , null , null );
84
- for (V1Pod item : list. getItems()) {
85
- System . out. println(item. getMetadata(). getName());
86
- }
87
- }
88
- }
89
- ```
90
-
91
- watch on namespace object:
92
-
93
- ``` java
94
- import com.google.gson.reflect.TypeToken ;
95
- import io.kubernetes.client.ApiClient ;
96
- import io.kubernetes.client.ApiException ;
97
- import io.kubernetes.client.Configuration ;
98
- import io.kubernetes.client.apis.CoreV1Api ;
99
- import io.kubernetes.client.models.V1Namespace ;
100
- import io.kubernetes.client.util.Config ;
101
- import io.kubernetes.client.util.Watch ;
102
-
103
- import java.io.IOException ;
104
-
105
- public class WatchExample {
106
- public static void main (String [] args ) throws IOException , ApiException {
107
- ApiClient client = Config . defaultClient();
108
- Configuration . setDefaultApiClient(client);
109
-
110
- CoreV1Api api = new CoreV1Api ();
111
-
112
- Watch<V1Namespace > watch = Watch . createWatch(
113
- client,
114
- api. listNamespaceCall(null , null , null , null , null , 5 , null , null , Boolean . TRUE , null , null ),
115
- new TypeToken<Watch .Response<V1Namespace > >(){}. getType());
116
-
117
- for (Watch . Response<V1Namespace > item : watch) {
118
- System . out. printf(" %s : %s%n" , item. type, item. object. getMetadata(). getName());
119
- }
120
- }
121
- }
122
- ```
64
+ We prepared a few examples for common use-cases which are shown below:
65
+ - __ Configuration__ :
66
+ - [ InClusterClientExample] ( https://github.com/kubernetes-client/java/blob/master/examples/src/main/java/io/kubernetes/client/examples/InClusterClientExample.java ) :
67
+ Configure a client while running inside the Kubernetes cluster.
68
+ - [ KubeConfigFileClientExample] ( https://github.com/kubernetes-client/java/blob/master/examples/src/main/java/io/kubernetes/client/examples/KubeConfigFileClientExample.java ) :
69
+ Configure a client to access a Kubernetes cluster from outside.
70
+ - __ Basics__ :
71
+ - [ SimpleExample] ( https://github.com/kubernetes-client/java/blob/master/examples/src/main/java/io/kubernetes/client/examples/Example.java ) :
72
+ Simple minimum example of how to use the client.
73
+ - [ ProtoExample] ( https://github.com/kubernetes-client/java/blob/master/examples/src/main/java/io/kubernetes/client/examples/ProtoExample.java ) :
74
+ Request/receive payloads in protobuf serialization protocol.
75
+ - [ PatchExample] ( https://github.com/kubernetes-client/java/blob/master/examples/src/main/java/io/kubernetes/client/examples/PatchExample.java ) :
76
+ Patch resource objects in various supported patch formats, equal to ` kubectl patch ` .
77
+ - [ FluentExample] ( https://github.com/kubernetes-client/java/blob/master/examples/src/main/java/io/kubernetes/client/examples/FluentExample.java ) :
78
+ Construct arbitrary resource in a fluent builder style.
79
+ - __ Streaming__ :
80
+ - [ WatchExample] ( https://github.com/kubernetes-client/java/blob/master/examples/src/main/java/io/kubernetes/client/examples/WatchExample.java ) :
81
+ Subscribe watch events from certain resources, equal to ` kubectl get <resource> -w ` .
82
+ - [ LogsExample] ( https://github.com/kubernetes-client/java/blob/master/examples/src/main/java/io/kubernetes/client/examples/LogsExample.java ) :
83
+ Fetch logs from running containers, equal to ` kubectl logs ` .
84
+ - [ ExecExample] ( https://github.com/kubernetes-client/java/blob/master/examples/src/main/java/io/kubernetes/client/examples/ExecExample.java ) :
85
+ Establish an "exec" session with running containers, equal to ` kubectl exec ` .
86
+ - [ PortForwardExample] ( https://github.com/kubernetes-client/java/blob/master/examples/src/main/java/io/kubernetes/client/examples/PortForwardExample.java ) :
87
+ Maps local port to a port on the pod, equal to ` kubectl port-forward ` .
88
+ - [ AttachExample] ( https://github.com/kubernetes-client/java/blob/master/examples/src/main/java/io/kubernetes/client/examples/AttachExample.java ) :
89
+ Attach to a process that is already running inside an existing container, equal to ` kubectl attach ` .
90
+ - [ CopyExample] ( https://github.com/kubernetes-client/java/blob/master/examples/src/main/java/io/kubernetes/client/examples/CopyExample.java ) :
91
+ Copy files and directories to and from containers, equal to ` kubectl cp ` .
92
+ - [ WebSocketExample] ( https://github.com/kubernetes-client/java/blob/master/examples/src/main/java/io/kubernetes/client/examples/WebSocketExample.java ) :
93
+ Establish an arbitrary web-socket session to certain resources.
94
+ - __ Advanced__ :
95
+ - [ InformerExample] ( https://github.com/kubernetes-client/java/blob/master/examples/src/main/java/io/kubernetes/client/examples/InformerExample.java ) :
96
+ Build an informer which list-watches resources and reflects the notifications to a local cache.
97
+ - [ LeaderElectionExample] ( https://github.com/kubernetes-client/java/blob/master/examples/src/main/java/io/kubernetes/client/examples/LeaderElectionExample.java ) :
98
+ Leader election utilities to help implement HA controllers.
99
+ - [ PagerExample] ( https://github.com/kubernetes-client/java/blob/master/examples/src/main/java/io/kubernetes/client/examples/PagerExample.java ) :
100
+ Support Pagination (only for the list request) to ease server-side loads/network congestion.
123
101
124
102
More examples can be found in [ examples] ( examples/ ) folder. To run examples, run this command:
125
103
0 commit comments