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; }
.withTargetPort(new IntOrString("https")) .endPort() .addToSelector("component", "api-server") .withType("LoadBalancer") .endSpec()
.endMetadata() .withNewSpec() .addToSelector("name", NAME) .withReplicas(1) .withNewTemplate()
.withNewMetadata().withName(serviceName).endMetadata() .withNewSpec() .addToSelector("app", "drools") .addNewPort().withPort(80).withNewTargetPort().withIntVal(8080).endTargetPort().endPort() .endSpec()
.withNewTargetPort(serviceModel.getTargetPort()) .endPort() .addToSelector(KubernetesConstants.KUBERNETES_SELECTOR_KEY, serviceModel.getSelector()) .withSessionAffinity(serviceModel.getSessionAffinity()) .withType(serviceModel.getServiceType())
private void ensureService(String name, DeploymentData deploymentData) { final Map<String, String> labels = prepareServiceLabels(deploymentData); final Map<String, String> annotations = prepareServiceAnnotations(deploymentData); openShiftClient.services().withName(name).createOrReplaceWithNew() .withNewMetadata() .withName(name) .addToAnnotations(annotations) .addToLabels(labels) .endMetadata() .withNewSpec() .addToSelector(INTEGRATION_NAME_LABEL, name) .addNewPort() .withName("http") .withProtocol("TCP") .withPort(INTEGRATION_SERVICE_PORT) .withNewTargetPort(INTEGRATION_SERVICE_PORT) .endPort() .endSpec() .done(); }
public void onTemplate(TemplateBuilder builder) { builder.addNewServiceObject() .withNewMetadata() .withName("elasticsearch-cluster") .endMetadata() .withNewSpec() .withClusterIP("None") .addNewPort() .withName("") .withProtocol("TCP") .withPort(9300) .withNewTargetPort(9300) .endPort() .addToSelector("component", "elasticsearch") .addToSelector("provider", "fabric8") .endSpec() .and() .build(); }