public BaseClient(String masterUrl) throws KubernetesClientException { this(new ConfigBuilder().withMasterUrl(masterUrl).build()); }
public static boolean isHttpsAvailable(Config config) { Config sslConfig = new ConfigBuilder(config) .withMasterUrl(Config.HTTPS_PROTOCOL_PREFIX + config.getMasterUrl()) .withRequestTimeout(1000) .withConnectionTimeout(1000) .build(); OkHttpClient client = HttpClientUtils.createHttpClient(config); try { Request request = new Request.Builder().get().url(sslConfig.getMasterUrl()) .build(); Response response = client.newCall(request).execute(); try (ResponseBody body = response.body()) { return response.isSuccessful(); } } catch (Throwable t) { LOG.warn("SSL handshake failed. Falling back to insecure connection."); } finally { if (client != null && client.connectionPool() != null) { client.connectionPool().evictAll(); } } return false; }
public static void main(String[] args) { if (args.length < 1) { System.out.println("Usage: podName [master] [namespace]"); return; } String podName = args[0]; String namespace = "default"; String master = "https://localhost:8443/"; if (args.length > 1) { master = args[1]; } if (args.length > 2) { namespace = args[2]; } System.out.println("Log of pod " + podName + " in " + namespace + " is:"); System.out.println("----------------------------------------------------------------"); Config config = new ConfigBuilder().withMasterUrl(master).build(); try (KubernetesClient client = new DefaultKubernetesClient(config); LogWatch watch = client.pods().inNamespace(namespace).withName(podName).tailingLines(10).watchLog(System.out)) { Thread.sleep(5 * 1000); } catch (Exception e) { logger.error(e.getMessage(), e); } } }
Config properties = new ConfigBuilder(base) .withMasterUrl(or(kubernetesClientProperties.getMasterUrl(), base.getMasterUrl())) .withApiVersion(or(kubernetesClientProperties.getApiVersion(),
public static void main(String[] args) { String master = "http://localhost:8080/"; if (args.length == 1) { master = args[0]; } io.fabric8.kubernetes.client.Config config = new io.fabric8.kubernetes.client.ConfigBuilder().withMasterUrl(master).build(); try (final KubernetesClient client = new DefaultKubernetesClient(config)) { StorageClassList storageClassList = client.storage().storageClasses().list(); logger.info(storageClassList.toString()); } catch (KubernetesClientException e) { logger.error(e.getMessage(), e); } } }
public static void main(String[] args) throws InterruptedException { String master = "https://localhost:8443/"; if (args.length == 1) { master = args[0]; } Config config = new ConfigBuilder().withMasterUrl(master) .withTrustCerts(true) .withUsername("admin") .withPassword("admin") .withNamespace("default") .build(); try (final KubernetesClient client = new AutoAdaptableKubernetesClient(config)) { log("Received pods", client.pods().list()); } catch (Exception e) { e.printStackTrace(); logger.error(e.getMessage(), e); Throwable[] suppressed = e.getSuppressed(); if (suppressed != null) { for (Throwable t : suppressed) { logger.error(t.getMessage(), t); } } } }
@Before public void setup() { this.kubernetesConfig = new ConfigBuilder() .withMasterUrl("https://2.2.2.2") .build(); this.version = "v1"; System.setProperty(OpenShiftConfig.KUBERNETES_OAPI_VERSION_SYSTEM_PROPERTY, this.version); }
public NamespacedKubernetesClient createClient() { Config config = new ConfigBuilder() .withMasterUrl(url("/")) .withTrustCerts(true) .withTlsVersions(TLS_1_0) .withNamespace("test") .build(); return new DefaultKubernetesClient(config); }
public static void main(String[] args) { try (DefaultKubernetesClient kubernetesClient = new DefaultKubernetesClient(new ConfigBuilder() .withMasterUrl("cluster_url") .withUsername("my_username") .withPassword("my_password") .build())) { final OpenShiftClient openShiftClient = kubernetesClient.adapt(OpenShiftClient.class); logger.info(openShiftClient.projects().list().toString()); } } }
public static void main(String[] args) throws InterruptedException { if (args.length < 1) { System.out.println("Usage: podName [master] [namespace]"); return; } String podName = args[0]; String namespace = "default"; String master = "https://localhost:8443/"; if (args.length > 1) { master = args[1]; } if (args.length > 2) { namespace = args[2]; } Config config = new ConfigBuilder().withMasterUrl(master).build(); try (final KubernetesClient client = new DefaultKubernetesClient(config); ExecWatch watch = client.pods().inNamespace(namespace).withName(podName) .readingInput(System.in) .writingOutput(System.out) .writingError(System.err) .withTTY() .usingListener(new SimpleListener()) .exec()){ Thread.sleep(10 * 1000); } }
public NamespacedKubernetesClient createClient() { Config config = new ConfigBuilder() .withMasterUrl(url("/")) .withTrustCerts(true) .withTlsVersions(TLS_1_0) .withNamespace("test") .build(); return new DefaultKubernetesClient(config); }
public NamespacedOpenShiftClient createOpenShiftClient() { Config config = new ConfigBuilder() .withMasterUrl(url("/")) .withNamespace("test") .withTrustCerts(true) .withTlsVersions(TLS_1_0) .build(); return new DefaultOpenShiftClient(config); } }
public NamespacedOpenShiftClient createOpenShiftClient() { Config config = new ConfigBuilder() .withMasterUrl(url("/")) .withNamespace("test") .withTrustCerts(true) .withTlsVersions(TLS_1_0) .build(); return new DefaultOpenShiftClient(config); } }
public static void main(String[] args) throws InterruptedException { String master = "https://localhost:8443/"; if (args.length == 1) { master = args[0]; } Config config = new ConfigBuilder().withMasterUrl(master).build(); try (OpenShiftClient client = new DefaultOpenShiftClient(config)) { ProjectRequest request = null; try { request = client.projectrequests().createNew().withNewMetadata().withName("thisisatest").endMetadata().withDescription("Jimmi").withDisplayName("Jimmi").done(); } finally { if (request != null) { client.projects().withName(request.getMetadata().getName()).delete(); } } } }
public static void main(String args[]) throws InterruptedException { String master = "https://192.168.99.100:8443/"; if (args.length == 1) { master = args[0]; } log("Using master with url ", master); Config config = new ConfigBuilder().withMasterUrl(master).build(); try (final KubernetesClient client = new DefaultKubernetesClient(config)) { final String namespace = "default"; PodDisruptionBudget podDisruptionBudget = new PodDisruptionBudgetBuilder() .withNewMetadata().withName("zk-pkb").endMetadata() .withNewSpec() .withMaxUnavailable(new IntOrString("1%")) .withNewSelector() .withMatchLabels(Collections.singletonMap("app", "zookeeper")) .endSelector() .endSpec() .build(); log("Current namespace is", namespace); client.policy().podDisruptionBudget().inNamespace(namespace).create(podDisruptionBudget); } catch (KubernetesClientException e) { log("Could not create resource", e.getMessage()); } }
public static void main(String[] args) throws InterruptedException { String namespace = "myproject"; String master = "CLUSTER_URL"; Config config = new ConfigBuilder().withMasterUrl(master).build(); OpenShiftClient client = new DefaultOpenShiftClient(config); try { ImageStreamTag istag = new ImageStreamTagBuilder().withNewMetadata().withName("bar1:1.0.12").endMetadata() .withNewTag().withNewFrom().withKind("DockerImage").withName("openshift/wildfly-81-centos7:latest").endFrom().endTag() .build(); log("Created istag", client.imageStreamTags().inNamespace(namespace).create(istag)); Thread.sleep(30000); }finally { log("ImageStreamTags are :"); log(client.imageStreamTags().inNamespace(namespace).withName("bar1:1.0.12").get().toString()); log("ImageStreamTags using list are :"); log(client.imageStreamTags().list().getItems().get(0).toString()); log("Deleted istag",client.imageStreamTags().withName("bar1:1.0.12").delete()); client.close(); } }
public static void main(String[] args) { String master = "https://localhost:8443/"; if (args.length == 1) { master = args[0]; } Config config = new ConfigBuilder().withMasterUrl(master).build(); KubernetesClient client = new DefaultKubernetesClient(config); try { log("Create namespace:", client.namespaces().create(new NamespaceBuilder().withNewMetadata().withName("thisisatest").endMetadata().build())); log("Deleted namespace:", client.namespaces().withName("test").delete()); log("Deleted testPod:", client.pods().inNamespace("thisisatest").withName("testpod").delete()); log("Deleted pod by label:", client.pods().withLabel("this", "works").delete()); } catch (KubernetesClientException e) { logger.error(e.getMessage(), e); } finally { client.namespaces().withName("thisisatest").delete(); client.close(); } }
public static void main(String args[]) throws InterruptedException { String master = "https://192.168.99.100:8443/"; if (args.length == 1) { master = args[0]; } log("Using master with url ", master); Config config = new ConfigBuilder().withMasterUrl(master).build(); try (final KubernetesClient client = new DefaultKubernetesClient(config)) { PriorityClass priorityClass = new PriorityClassBuilder() .withNewMetadata().withName("high-priority").endMetadata() .withValue(new Integer(100000)) .withGlobalDefault(false) .withDescription("This priority class should be used for XYZ service pods only.") .build(); client.scheduling().priorityClass().create(priorityClass); client.pods().inNamespace("default").create(new PodBuilder() .withNewMetadata().withName("nginx").withLabels(Collections.singletonMap("env", "test")).endMetadata() .withNewSpec() .addToContainers(new ContainerBuilder().withName("nginx").withImage("nginx").withImagePullPolicy("IfNotPresent").build()) .withPriorityClassName("high-priority") .endSpec() .build() ); } catch (KubernetesClientException e) { e.printStackTrace(); log("Could not create resource", e.getMessage()); } }
public static void main(String args[]) { String master = "https://localhost:8443/"; if (args.length == 1) { master = args[0]; } Config config = new ConfigBuilder().withMasterUrl(master).build(); try(final OpenShiftClient client = new DefaultOpenShiftClient(config)) { VersionInfo versionInfo = client.getVersion(); log("Version details of this OpenShift cluster :-"); log("Major : ", versionInfo.getMajor()); log("Minor : ", versionInfo.getMinor()); log("GitVersion : ", versionInfo.getGitVersion()); log("BuildDate : ", versionInfo.getBuildDate()); log("GitTreeState : ", versionInfo.getGitTreeState()); log("Platform : ", versionInfo.getPlatform()); log("GitVersion : ", versionInfo.getGitVersion()); log("GoVersion : ", versionInfo.getGoVersion()); log("GitCommit : ", versionInfo.getGitCommit()); } }
public static void main(String args[]) { String master = "https://localhost:8443/"; if (args.length == 1) { master = args[0]; } Config config = new ConfigBuilder().withMasterUrl(master).build(); try(final KubernetesClient client = new DefaultKubernetesClient(config)) { VersionInfo versionInfo = client.getVersion(); log("Version details of this Kubernetes cluster :-"); log("Major : ", versionInfo.getMajor()); log("Minor : ", versionInfo.getMinor()); log("GitVersion : ", versionInfo.getGitVersion()); log("BuildDate : ", versionInfo.getBuildDate()); log("GitTreeState : ", versionInfo.getGitTreeState()); log("Platform : ", versionInfo.getPlatform()); log("GitVersion : ", versionInfo.getGitVersion()); log("GoVersion : ", versionInfo.getGoVersion()); log("GitCommit : ", versionInfo.getGitCommit()); } }