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()); } }
KubernetesConstants.KUBERNETES_PODS_LABELS, Map.class); Pod podCreating = new PodBuilder().withNewMetadata() .withName(podName).withLabels(labels).endMetadata() .withSpec(podSpec).build(); pod = getEndpoint().getKubernetesClient().pods()
metadataBuilder.withLabels(labels);
.withAnnotations(podAnnotations).withLabels(podLabels); if (!Strings.isNullOrEmpty(template.getMetadata().getName())) { metadataBuilder.withName(template.getMetadata().getName());
.withLabels(TILLER_LABELS) .endMetadata()
@Test public void shouldCombineAllLabels() { Pod pod1 = new PodBuilder().withNewMetadata().withLabels( // ImmutableMap.of("label1", "pod1", "label2", "pod1") // ).endMetadata().withNewSpec().endSpec().build(); Pod pod2 = new PodBuilder().withNewMetadata().withLabels( // ImmutableMap.of("label1", "pod2", "label3", "pod2") // ).endMetadata().withNewSpec().endSpec().build(); Map<String, String> labels = combine(pod1, pod2).getMetadata().getLabels(); assertThat(labels, hasEntry("label1", "pod2")); assertThat(labels, hasEntry("label2", "pod1")); assertThat(labels, hasEntry("label3", "pod2")); }
@Before public void configureCloud() throws Exception { client = setupCloud(this).connect(); deletePods(client, getLabels(this), false); String image = "busybox"; Container c = new ContainerBuilder().withName(image).withImagePullPolicy("IfNotPresent").withImage(image) .withCommand("cat").withTty(true).build(); String podName = "test-command-execution-" + RandomStringUtils.random(5, "bcdfghjklmnpqrstvwxz0123456789"); pod = client.pods().create(new PodBuilder().withNewMetadata().withName(podName).withLabels(getLabels(this)) .endMetadata().withNewSpec().withContainers(c).endSpec().build()); System.out.println("Created pod: " + pod.getMetadata().getName()); decorator = new ContainerExecDecorator(client, pod.getMetadata().getName(), image, client.getNamespace()); }
private void launchPod(String appId, PodSpec podSpec, Map<String, String> labelMap, Map<String, String> idMap, Map<String, String> annotations) { client.pods() .createNew() .withNewMetadata() .withName(appId) .withLabels(labelMap) .withAnnotations(annotations) .addToLabels(idMap) .endMetadata() .withSpec(podSpec) .done(); }