private void createConfigMap(Map<String, String> data) { LOGGER.debug("Creating new config map with data: {}", data); ConfigMap newConfigMap = new ConfigMapBuilder().withNewMetadata() .withName(leaderProperties.getConfigMapName()) .addToLabels(PROVIDER_KEY, PROVIDER) .addToLabels(KIND_KEY, KIND) .endMetadata() .addToData(data) .build(); kubernetesClient.configMaps() .inNamespace(leaderProperties.getNamespace(kubernetesClient.getNamespace())) .create(newConfigMap); }
build(); client.customResourceDefinitions().create(dummyCRD); System.out.println("Created CRD " + dummyCRD.getMetadata().getName());
try (KubernetesClient client = new DefaultKubernetesClient(config)) { try { log("Create namespace:", client.namespaces().create(new NamespaceBuilder().withNewMetadata().withName("thisisatest").endMetadata().build()));
System.out.println("Creating pod in namespace " + namespace); NonNamespaceOperation<Pod, PodList, DoneablePod, PodResource<Pod, DoneablePod>> pods = client.pods().inNamespace(namespace); Pod result = pods.create(pod); System.out.println("Created pod " + result.getMetadata().getName()); } else {
log("Created namespace", client.namespaces().create(ns)); log("Create resource quota", client.resourceQuotas().inNamespace("thisisatest").create(quota)); .endSpec().build(); log("Created RC", client.replicationControllers().inNamespace("thisisatest").create(rc)); log("Deleted RC"); log("Created RC", client.replicationControllers().inNamespace("thisisatest").create(rc)); client.replicationControllers().inAnyNamespace().withLabel("server", "nginx").delete(); log("Deleted RC by label"); log("Created RC", client.replicationControllers().inNamespace("thisisatest").create(rc)); client.replicationControllers().inNamespace("thisisatest").withField("metadata.name", "nginx-controller").delete(); log("Deleted RC by field");
deployment = client.apps().deployments().inNamespace("thisisatest").create(deployment); log("Created deployment", deployment);
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) throws InterruptedException { try (OpenShiftClient client = new DefaultOpenShiftClient()) { SecurityContextConstraints scc = new SecurityContextConstraintsBuilder() .withNewMetadata().withName("scc").endMetadata() .withAllowPrivilegedContainer(true) .withNewRunAsUser() .withType("RunAsAny") .endRunAsUser() .withNewSeLinuxContext() .withType("RunAsAny") .endSeLinuxContext() .withNewFsGroup() .withType("RunAsAny") .endFsGroup() .withNewSupplementalGroups() .withType("RunAsAny") .endSupplementalGroups() .addToUsers("admin") .addToGroups("admin-group") .build(); log("Created SecurityContextConstraints", client.securityContextConstraints().create(scc)); client.close(); } catch (KubernetesClientException e) { logger.error(e.getMessage(), e); } }
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()); } }
.build(); log("Created ImageStream", client.imageStreams().inNamespace(namespace).create(imageStream));
@Override public void createResource(KafkaTopic topicResource, Handler<AsyncResult<Void>> handler) { vertx.executeBlocking(future -> { try { operation().inNamespace(namespace).create(topicResource); future.complete(); } catch (Exception e) { future.fail(e); } }, handler); }
.build(); client.persistentVolumes().create(pv); log("Successfully created Persistent Volume object"); } catch (KubernetesClientException e) {
.build(); client.autoscaling().horizontalPodAutoscalers().inNamespace("default").create(horizontalPodAutoscaler); } catch (KubernetesClientException e) { logger.error(e.getMessage(), e);
cronJob1 = client.batch().cronjobs().inNamespace(namespace).create(cronJob1); log("Successfully created cronjob with name ", cronJob1.getMetadata().getName());
public static void main(String args[]) { try (final KubernetesClient client = new DefaultKubernetesClient()) { Service service = new ServiceBuilder() .withNewMetadata() .withName("my-service") .endMetadata() .withNewSpec() .withSelector(Collections.singletonMap("app", "MyApp")) .addNewPort() .withName("test-port") .withProtocol("TCP") .withPort(80) .withTargetPort(new IntOrString(9376)) .endPort() .withType("LoadBalancer") .endSpec() .withNewStatus() .withNewLoadBalancer() .addNewIngress() .withIp("146.148.47.155") .endIngress() .endLoadBalancer() .endStatus() .build(); service = client.services().inNamespace(client.getNamespace()).create(service); log("Created service with name ", service.getMetadata().getName()); String serviceURL = client.services().inNamespace(client.getNamespace()).withName(service.getMetadata().getName()).getURL("test-port"); log("Service URL", serviceURL); } }