24
24
import io .kubernetes .client .models .V1PodList ;
25
25
import io .kubernetes .client .models .V1ServiceList ;
26
26
import io .kubernetes .client .util .Config ;
27
+ import java .io .IOException ;
27
28
import java .util .List ;
28
29
import java .util .Optional ;
29
30
import java .util .logging .Level ;
@@ -49,21 +50,24 @@ public class Example {
49
50
For API_SERVER_NAME, you can get the server name as follows.
50
51
$ kubectl cluster-info|grep master
51
52
Kubernetes master is running at https://*****************.hcp.japaneast.azmk8s.io:443
52
- */
53
+ */
53
54
private final static String API_SERVER_NAME = "https://*****************.hcp.japaneast.azmk8s.io" ;
54
55
/*
55
56
For ACCESS_TOKEN , you can get the token as follows
56
57
$ kubectl describe secret $(kubectl get secrets | grep default | cut -f1 -d ' ') | grep -E '^token' | cut -f2 -d':' | tr -d '\t'
57
- */
58
+ */
58
59
private static final String ACCESS_TOKEN = "********************************" ;
59
60
60
61
private final static Logger LOGGER = Logger .getLogger (Example .class .getName ());
61
62
62
63
/**
63
64
* Constructor
65
+ * @throws java.io.IOException
64
66
*/
65
- public Example () {
66
- ApiClient client = Config .fromToken (API_SERVER_NAME , ACCESS_TOKEN , false );
67
+ public Example () throws IOException {
68
+ ApiClient client = Config .defaultClient ();
69
+ //If you want to use specific k8s cluster and access token, please use following?
70
+ //ApiClient client = Config.fromToken(API_SERVER_NAME, ACCESS_TOKEN, false);
67
71
Configuration .setDefaultApiClient (client );
68
72
corev1Api = new CoreV1Api (client );
69
73
}
@@ -77,8 +81,8 @@ public static void main(String[] args) {
77
81
try {
78
82
Example operation = new Example ();
79
83
operation .executeCommand ();
80
- } catch (ApiException ex ) {
81
- LOGGER .log (Level .SEVERE , null , ex );
84
+ } catch (ApiException | IOException ex ) {
85
+ Logger . getLogger ( Example . class . getName ()) .log (Level .SEVERE , null , ex );
82
86
}
83
87
}
84
88
@@ -201,7 +205,7 @@ public List<String> getServices() throws ApiException {
201
205
public void scaleDeployment (String deploymentName , int numberOfReplicas ) throws ApiException {
202
206
ExtensionsV1beta1Api extensionV1Api = new ExtensionsV1beta1Api ();
203
207
extensionV1Api .setApiClient (corev1Api .getApiClient ());
204
- ExtensionsV1beta1DeploymentList listNamespacedDeployment = extensionV1Api .listNamespacedDeployment (DEFAULT_NAME_SPACE ,null ,null ,null ,Boolean .FALSE ,null ,null ,null ,null ,Boolean .FALSE );
208
+ ExtensionsV1beta1DeploymentList listNamespacedDeployment = extensionV1Api .listNamespacedDeployment (DEFAULT_NAME_SPACE , null , null , null , Boolean .FALSE , null , null , null , null , Boolean .FALSE );
205
209
206
210
List <ExtensionsV1beta1Deployment > extensionsV1beta1DeploymentItems = listNamespacedDeployment .getItems ();
207
211
Optional <ExtensionsV1beta1Deployment > findedDeployment = extensionsV1beta1DeploymentItems .stream ()
0 commit comments