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); } }
@Before public void setup() { pod = new PodBuilder().withNewMetadata().withName("pod1").withNamespace("test").and().build(); service = new ServiceBuilder() .withNewMetadata().withName("service1").withNamespace("test").and() .build(); final ReplicationController rc = new ReplicationControllerBuilder() .withNewMetadata().withName("repl1").withNamespace("test").endMetadata() .withNewSpec().withReplicas(1).endSpec() .build(); kubeList = new KubernetesListBuilder().withItems(pod, service, rc).build(); }
KubernetesConstants.KUBERNETES_SERVICE_LABELS, Map.class); Service serviceCreating = new ServiceBuilder() .withNewMetadata().withName(serviceName).withLabels(labels) .endMetadata().withSpec(serviceSpec).build(); service = getEndpoint().getKubernetesClient().services()
@Override protected ObjectMeta getOrCreateMetadata(ServiceBuilder item) { return item.hasMetadata() ? item.buildMetadata() : item.withNewMetadata().endMetadata().buildMetadata(); } }
protected Service exposeService(String namespace, Map<String, String> metadata, String serviceName, Iterable<Integer> inboundPorts) { List<ServicePort> servicePorts = Lists.newArrayList(); for (Integer inboundPort : inboundPorts) { servicePorts.add(new ServicePortBuilder().withName(Integer.toString(inboundPort)).withPort(inboundPort).build()); } Service service = new ServiceBuilder().withNewMetadata().withName(serviceName).endMetadata() .withNewSpec() .addToSelector(metadata) .addToPorts(Iterables.toArray(servicePorts, ServicePort.class)) .withType(NODE_PORT) .endSpec() .build(); client.services().inNamespace(namespace).create(service); service = getService(namespace, serviceName); LOG.debug("Exposed service {} in namespace {}.", service, namespace); return service; }
@Override protected Service resource() { return new ServiceBuilder().withNewMetadata().withNamespace(NAMESPACE).withName(RESOURCE_NAME).endMetadata().build(); }
protected Service createService(String name, String type, List<ServicePort> ports, Map<String, String> labels, Map<String, String> selector, Map<String, String> annotations) { Service service = new ServiceBuilder() .withNewMetadata() .withName(name) .withLabels(labels) .withNamespace(namespace) .withAnnotations(annotations) .withOwnerReferences(createOwnerReference()) .endMetadata() .withNewSpec() .withType(type) .withSelector(selector) .withPorts(ports) .endSpec() .build(); log.trace("Created service {}", service); return service; }
.withNewMetadata() .withName(service.getName()) .withAnnotations(getAnnotations(service))
private static Service getMessagingClientServiceResource() { return new ServiceBuilder() .withNewMetadata() .withName(SystemtestsOpenshiftApp.MESSAGING_CLIENTS.toString()) .addToLabels("run", SystemtestsOpenshiftApp.MESSAGING_CLIENTS.toString()) .endMetadata() .withNewSpec() .withSelector(Collections.singletonMap("app", SystemtestsOpenshiftApp.MESSAGING_CLIENTS.toString())) .addNewPort() .withName("http") .withPort(4242) .withProtocol("TCP") .endPort() .endSpec() .build(); } }
protected Service createHeadlessService(List<ServicePort> ports, Map<String, String> annotations) { Service service = new ServiceBuilder() .withNewMetadata() .withName(headlessServiceName) .withLabels(getLabelsWithName(headlessServiceName, templateHeadlessServiceLabels)) .withNamespace(namespace) .withAnnotations(mergeAnnotations(annotations, templateHeadlessServiceAnnotations)) .withOwnerReferences(createOwnerReference()) .endMetadata() .withNewSpec() .withType("ClusterIP") .withClusterIP("None") .withSelector(getSelectorLabels()) .withPorts(ports) .endSpec() .build(); log.trace("Created headless service {}", service); return service; }
private Service getDefaultService() { // No image config, no service if (!hasImageConfiguration()) { return null; } String serviceName = getConfig(Config.name, MavenUtil.createDefaultResourceName(getContext().getGav().getSanitizedArtifactId())); // Create service only for all images which are supposed to live in a single pod List<ServicePort> ports = extractPorts(getImages().get()); ServiceBuilder builder = new ServiceBuilder() .withNewMetadata() .withName(serviceName) .withLabels(extractLabels()) .endMetadata(); ServiceFluent.SpecNested<ServiceBuilder> specBuilder = builder.withNewSpec(); if (!ports.isEmpty()) { specBuilder.withPorts(ports); } else if (Configs.asBoolean(getConfig(Config.headless))) { specBuilder.withClusterIP("None"); } else { // No ports, no headless --> no service return null; } if (hasConfig(Config.type)) { specBuilder.withType(getConfig(Config.type)); } specBuilder.endSpec(); return builder.build(); }
private Service getDefaultService() { // No image config, no service if (!hasImageConfiguration()) { return null; } // Create service only for all images which are supposed to live in a single pod List<ServicePort> ports = extractPorts(getImages()); ServiceBuilder builder = new ServiceBuilder() .withNewMetadata() .withName(getConfig(Config.name, MavenUtil.createDefaultResourceName(getProject()))) .withLabels(extractLabels()) .endMetadata(); ServiceFluent.SpecNested<ServiceBuilder> specBuilder = builder.withNewSpec(); if (!ports.isEmpty()) { specBuilder.withPorts(ports); } else if (Configs.asBoolean(getConfig(Config.headless))) { specBuilder.withClusterIP("None"); } else { // No ports, no headless --> no service return null; } if (hasConfig(Config.type)) { specBuilder.withType(getConfig(Config.type)); } specBuilder.endSpec(); return builder.build(); }
.withNewMetadata() .withName(serviceName) .withNamespace(namespace)
.withNewMetadata() .withName(serviceName) .withNamespace(namespace)
.withNewMetadata() .withName(serviceModel.getName()) .withNamespace(dataHolder.getNamespace())
.withNewMetadata() .withNamespace(NAMESPACE) .withName(RESOURCE_NAME) .withNewMetadata() .withNamespace(NAMESPACE) .withName(RESOURCE_NAME)