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; }