本文整理汇总了Java中io.fabric8.kubernetes.api.model.ContainerPort类的典型用法代码示例。如果您正苦于以下问题:Java ContainerPort类的具体用法?Java ContainerPort怎么用?Java ContainerPort使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ContainerPort类属于io.fabric8.kubernetes.api.model包,在下文中一共展示了ContainerPort类的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: createWithPorts
import io.fabric8.kubernetes.api.model.ContainerPort; //导入依赖的package包/类
@Test
public void createWithPorts() {
KubernetesDeployerProperties kubernetesDeployerProperties = new KubernetesDeployerProperties();
DefaultContainerFactory defaultContainerFactory = new DefaultContainerFactory(
kubernetesDeployerProperties);
AppDefinition definition = new AppDefinition("app-test", null);
Resource resource = getResource();
Map<String, String> props = new HashMap<>();
props.put("spring.cloud.deployer.kubernetes.containerPorts",
"8081, 8082, 65535");
AppDeploymentRequest appDeploymentRequest = new AppDeploymentRequest(definition,
resource, props);
Container container = defaultContainerFactory.create("app-test",
appDeploymentRequest, null, null, false);
assertNotNull(container);
List<ContainerPort> containerPorts = container.getPorts();
assertNotNull(containerPorts);
assertTrue("There should be three ports set", containerPorts.size() == 3);
assertTrue(8081 == containerPorts.get(0).getContainerPort());
assertTrue(8082 == containerPorts.get(1).getContainerPort());
assertTrue(65535 == containerPorts.get(2).getContainerPort());
}
开发者ID:spring-cloud,项目名称:spring-cloud-deployer-kubernetes,代码行数:25,代码来源:DefaultContainerFactoryTests.java
示例2: findHostPortForService
import io.fabric8.kubernetes.api.model.ContainerPort; //导入依赖的package包/类
public static int findHostPortForService(Pod pod, int serviceContainerPort) {
List<Container> containers = KubernetesHelper.getContainers(pod);
for (Container container : containers) {
List<ContainerPort> ports = container.getPorts();
if (ports != null) {
for (ContainerPort port : ports) {
Integer containerPort = port.getContainerPort();
Integer hostPort = port.getHostPort();
if (containerPort != null && containerPort == serviceContainerPort) {
if (hostPort != null) {
return hostPort;
}
}
}
}
}
LOG.warn("Could not find host port for service port: {} pod: {}", serviceContainerPort, pod);
return serviceContainerPort;
}
开发者ID:fabric8io,项目名称:jube,代码行数:20,代码来源:NodeHelper.java
示例3: createPodSpec
import io.fabric8.kubernetes.api.model.ContainerPort; //导入依赖的package包/类
private PodSpec createPodSpec() throws IOException {
PodSpec podSpec = new PodSpec();
podSpec.setHostname("localhost");
Container container = new Container();
container.setImage("docker.io/wildflyext/wildfly-camel:latest");
container.setName("wildfly-camel-test");
ContainerPort port = new ContainerPort();
port.setHostIP("0.0.0.0");
port.setContainerPort(8080);
List<ContainerPort> ports = new ArrayList<>();
ports.add(port);
container.setPorts(ports);
List<Container> containers = new ArrayList<>();
containers.add(container);
podSpec.setContainers(containers);
return podSpec;
}
开发者ID:wildfly-extras,项目名称:wildfly-camel,代码行数:24,代码来源:KubernetesIntegrationTest.java
示例4: createWithPortAndHostNetwork
import io.fabric8.kubernetes.api.model.ContainerPort; //导入依赖的package包/类
@Test
public void createWithPortAndHostNetwork() {
KubernetesDeployerProperties kubernetesDeployerProperties = new KubernetesDeployerProperties();
DefaultContainerFactory defaultContainerFactory = new DefaultContainerFactory(
kubernetesDeployerProperties);
AppDefinition definition = new AppDefinition("app-test", null);
Resource resource = getResource();
Map<String, String> props = new HashMap<>();
props.put("spring.cloud.deployer.kubernetes.containerPorts",
"8081, 8082, 65535");
AppDeploymentRequest appDeploymentRequest = new AppDeploymentRequest(definition,
resource, props);
Container container = defaultContainerFactory.create("app-test",
appDeploymentRequest, null, null, true);
assertNotNull(container);
List<ContainerPort> containerPorts = container.getPorts();
assertNotNull(containerPorts);
assertTrue("There should be three container ports set", containerPorts.size() == 3);
assertTrue(8081 == containerPorts.get(0).getContainerPort());
assertTrue(8081 == containerPorts.get(0).getHostPort());
assertTrue(8082 == containerPorts.get(1).getContainerPort());
assertTrue(8082 == containerPorts.get(1).getHostPort());
assertTrue(65535 == containerPorts.get(2).getContainerPort());
assertTrue(65535 == containerPorts.get(2).getHostPort());
}
开发者ID:spring-cloud,项目名称:spring-cloud-deployer-kubernetes,代码行数:28,代码来源:DefaultContainerFactoryTests.java
示例5: getPortMap
import io.fabric8.kubernetes.api.model.ContainerPort; //导入依赖的package包/类
private static Map<String, Map<String, Integer>> getPortMap(List<Container> containers) {
Map<String, Map<String, Integer>> portMap = new LinkedHashMap<>();
for (Container container : containers) {
Map<String, Integer> ports = new LinkedHashMap<>();
for (ContainerPort port : container.getPorts()) {
ports.put(port.getName(), port.getContainerPort());
}
portMap.put(container.getName(), ports);
}
return portMap;
}
开发者ID:EnMasseProject,项目名称:enmasse,代码行数:12,代码来源:Pod.java
示例6: exposePort
import io.fabric8.kubernetes.api.model.ContainerPort; //导入依赖的package包/类
private Map<String, ServicePort> exposePort(Collection<? extends ServerConfig> serverConfig) {
Map<String, ServicePort> exposedPorts = new HashMap<>();
Set<String> portsToExpose =
serverConfig.stream().map(ServerConfig::getPort).collect(Collectors.toSet());
for (String portToExpose : portsToExpose) {
String[] portProtocol = portToExpose.split("/");
int port = parseInt(portProtocol[0]);
String protocol = portProtocol.length > 1 ? portProtocol[1].toUpperCase() : "TCP";
Optional<ContainerPort> exposedOpt =
container
.getPorts()
.stream()
.filter(p -> p.getContainerPort().equals(port) && protocol.equals(p.getProtocol()))
.findAny();
ContainerPort containerPort;
if (exposedOpt.isPresent()) {
containerPort = exposedOpt.get();
} else {
containerPort =
new ContainerPortBuilder().withContainerPort(port).withProtocol(protocol).build();
container.getPorts().add(containerPort);
}
exposedPorts.put(
portToExpose,
new ServicePortBuilder()
.withName("server-" + containerPort.getContainerPort())
.withPort(containerPort.getContainerPort())
.withProtocol(protocol)
.withNewTargetPort(containerPort.getContainerPort())
.build());
}
return exposedPorts;
}
开发者ID:eclipse,项目名称:che,代码行数:37,代码来源:ServerExposer.java
示例7: mockContainer
import io.fabric8.kubernetes.api.model.ContainerPort; //导入依赖的package包/类
private static Container mockContainer(String name, int... ports) {
final Container container = mock(Container.class);
when(container.getName()).thenReturn(name);
final List<ContainerPort> containerPorts = new ArrayList<>(ports.length);
for (int port : ports) {
containerPorts.add(new ContainerPortBuilder().withContainerPort(port).build());
}
when(container.getPorts()).thenReturn(containerPorts);
return container;
}
开发者ID:eclipse,项目名称:che,代码行数:11,代码来源:OpenShiftInternalRuntimeTest.java
示例8: toPort
import io.fabric8.kubernetes.api.model.ContainerPort; //导入依赖的package包/类
public ContainerPort toPort() {
ContainerPort p = new ContainerPort();
p.setName(name);
p.setContainerPort(containerPort);
if(hostPort != null) {
p.setHostPort(hostPort);
}
return p;
}
开发者ID:carlossg,项目名称:jenkins-kubernetes-plugin,代码行数:10,代码来源:PortMapping.java
示例9: findPortWithContainerPort
import io.fabric8.kubernetes.api.model.ContainerPort; //导入依赖的package包/类
public static ContainerPort findPortWithContainerPort(List<ContainerPort> ports, int containerPortNumber) {
for (ContainerPort port : ports) {
Integer containerPort = port.getContainerPort();
if (containerPort != null && containerPort == containerPortNumber) {
return port;
}
}
return null;
}
开发者ID:fabric8io,项目名称:jube,代码行数:10,代码来源:NodeHelper.java
示例10: convertPortMappings
import io.fabric8.kubernetes.api.model.ContainerPort; //导入依赖的package包/类
/**
* Convert stratos port mappings to kubernetes container ports
*
* @param portMappings
* @return
*/
public static List<ContainerPort> convertPortMappings(List<PortMapping> portMappings) {
List<ContainerPort> ports = new ArrayList<ContainerPort>();
for (PortMapping portMapping : portMappings) {
ContainerPort containerPort = new ContainerPort();
containerPort.setName(preparePortNameFromPortMapping(portMapping));
containerPort.setContainerPort(portMapping.getPort());
ports.add(containerPort);
}
return ports;
}
开发者ID:apache,项目名称:stratos,代码行数:17,代码来源:KubernetesIaasUtil.java
示例11: toContainerPort
import io.fabric8.kubernetes.api.model.ContainerPort; //导入依赖的package包/类
public ContainerPort toContainerPort() {
return new ContainerPortBuilder().withName(getName()).withContainerPort(port).build();
}
开发者ID:StuPro-TOSCAna,项目名称:TOSCAna,代码行数:4,代码来源:Port.java
示例12: getOpenContainerPorts
import io.fabric8.kubernetes.api.model.ContainerPort; //导入依赖的package包/类
public List<ContainerPort> getOpenContainerPorts() {
List<ContainerPort> ports = new ArrayList<>();
openPorts.forEach(e -> ports.add(new ContainerPortBuilder().withContainerPort(e).build()));
return Collections.unmodifiableList(ports);
}
开发者ID:StuPro-TOSCAna,项目名称:TOSCAna,代码行数:6,代码来源:NodeStack.java
示例13: createContainer
import io.fabric8.kubernetes.api.model.ContainerPort; //导入依赖的package包/类
protected Container createContainer(final String imageName,
final ImagePullPolicy imagePullPolicy,
final String namespace,
final boolean tls,
final boolean verifyTls) {
final Container container = new Container();
container.setName(DEFAULT_NAME);
container.setImage(normalizeImageName(imageName));
container.setImagePullPolicy(normalizeImagePullPolicy(imagePullPolicy));
final ContainerPort containerPort = new ContainerPort();
containerPort.setContainerPort(Integer.valueOf(44134));
containerPort.setName(DEFAULT_NAME);
container.setPorts(Arrays.asList(containerPort));
final List<EnvVar> env = new ArrayList<>();
final EnvVar tillerNamespace = new EnvVar();
tillerNamespace.setName("TILLER_NAMESPACE");
tillerNamespace.setValue(normalizeNamespace(namespace));
env.add(tillerNamespace);
if (tls) {
final EnvVar tlsVerify = new EnvVar();
tlsVerify.setName("TILLER_TLS_VERIFY");
tlsVerify.setValue(verifyTls ? "1" : "");
env.add(tlsVerify);
final EnvVar tlsEnable = new EnvVar();
tlsEnable.setName("TILLER_TLS_ENABLE");
tlsEnable.setValue("1");
env.add(tlsEnable);
final EnvVar tlsCerts = new EnvVar();
tlsCerts.setName("TILLER_TLS_CERTS");
tlsCerts.setValue(TILLER_TLS_CERTS_PATH);
env.add(tlsCerts);
}
container.setEnv(env);
final IntOrString port44135 = new IntOrString(Integer.valueOf(44135));
final HTTPGetAction livenessHttpGetAction = new HTTPGetAction();
livenessHttpGetAction.setPath("/liveness");
livenessHttpGetAction.setPort(port44135);
final Probe livenessProbe = new Probe();
livenessProbe.setHttpGet(livenessHttpGetAction);
livenessProbe.setInitialDelaySeconds(ONE);
livenessProbe.setTimeoutSeconds(ONE);
container.setLivenessProbe(livenessProbe);
final HTTPGetAction readinessHttpGetAction = new HTTPGetAction();
readinessHttpGetAction.setPath("/readiness");
readinessHttpGetAction.setPort(port44135);
final Probe readinessProbe = new Probe();
readinessProbe.setHttpGet(readinessHttpGetAction);
readinessProbe.setInitialDelaySeconds(ONE);
readinessProbe.setTimeoutSeconds(ONE);
container.setReadinessProbe(readinessProbe);
if (tls) {
final VolumeMount volumeMount = new VolumeMount();
volumeMount.setName(DEFAULT_NAME + "-certs");
volumeMount.setReadOnly(true);
volumeMount.setMountPath(TILLER_TLS_CERTS_PATH);
container.setVolumeMounts(Arrays.asList(volumeMount));
}
return container;
}
开发者ID:microbean,项目名称:microbean-helm,代码行数:73,代码来源:TillerInstaller.java
示例14: createContainerPorts
import io.fabric8.kubernetes.api.model.ContainerPort; //导入依赖的package包/类
private Collection<ContainerPort> createContainerPorts(final DockerComponent dockerC, final EnvironmentContext ctx) {
return dockerC.ports().foldRight(List.<ContainerPort>empty(), (namePort, list) -> {
return list.append(newContainerPort(namePort._2));
}).toJavaList();
}
开发者ID:fabzo,项目名称:kraken,代码行数:6,代码来源:KubernetesLifecycleHandler.java
示例15: newContainerPort
import io.fabric8.kubernetes.api.model.ContainerPort; //导入依赖的package包/类
private ContainerPort newContainerPort(final int port) {
return new ContainerPortBuilder().withContainerPort(port).build();
}
开发者ID:fabzo,项目名称:kraken,代码行数:4,代码来源:KubernetesLifecycleHandler.java
示例16: executePod
import io.fabric8.kubernetes.api.model.ContainerPort; //导入依赖的package包/类
@Override
protected void executePod(Pod podInfo, String podId) {
System.out.println("Created: " + podInfo.getMetadata().getCreationTimestamp());
System.out.println("Labels: ");
Map<String, String> labels = podInfo.getMetadata().getLabels();
for (Map.Entry<String, String> entry : labels.entrySet()) {
System.out.println(indent + entry.getKey() + " = " + entry.getValue());
}
PodStatus currentState = podInfo.getStatus();
if (currentState != null) {
printValue("Host", currentState.getHostIP());
printValue("IP", currentState.getPodIP());
printValue("Status", getStatusText(currentState));
}
PodSpec spec = podInfo.getSpec();
if (spec != null) {
List<Container> containers = spec.getContainers();
if (notEmpty(containers)) {
System.out.println("Containers:");
indentCount++;
for (Container container : containers) {
printValue("Name", container.getName());
printValue("Image", container.getImage());
printValue("Working Dir", container.getWorkingDir());
printValue("Command", container.getCommand());
List<ContainerPort> ports = container.getPorts();
if (notEmpty(ports)) {
println("Ports:");
indentCount++;
for (ContainerPort port : ports) {
printValue("Name", port.getName());
printValue("Protocol", port.getProtocol());
printValue("Host Port", port.getHostPort());
printValue("Container Port", port.getContainerPort());
}
indentCount--;
}
List<EnvVar> envList = container.getEnv();
if (notEmpty(envList)) {
println("Environment:");
indentCount++;
for (EnvVar env : envList) {
printValue(env.getName(), env.getValue());
}
indentCount--;
}
List<VolumeMount> volumeMounts = container.getVolumeMounts();
if (notEmpty(volumeMounts)) {
println("Volume Mounts:");
indentCount++;
for (VolumeMount volumeMount : volumeMounts) {
printValue("Name", volumeMount.getName());
printValue("Mount Path", volumeMount.getMountPath());
printValue("Read Only", volumeMount.getReadOnly());
}
indentCount--;
}
}
}
List<Volume> volumes = spec.getVolumes();
if (volumes != null) {
System.out.println("Volumes: ");
for (Volume volume : volumes) {
System.out.println(indent + volume.getName());
}
}
}
}
开发者ID:fabric8io,项目名称:fabric8-forge,代码行数:72,代码来源:PodInfo.java
示例17: createPod
import io.fabric8.kubernetes.api.model.ContainerPort; //导入依赖的package包/类
/**
* Create pod.
*
* @param podId id of the pod
* @param podName pod label
* @param podLabels Map of labels to be applied to the pod
* @param annotations Map of annotations to be applied to the pod
* @param dockerImage docker image name
* @param cpu number of cpu cores
* @param memory memory allocation in mega bytes
* @param ports ports to be opened
* @param environmentVariables environment variables
* @param imagePullSecrets Image Pull Secret to be passed to the pod
* @param imagePullPolicy Image Pull policy to be passed to the pod
* @throws KubernetesClientException
*/
public void createPod(String podId, String podName, Map<String, String> podLabels, Map<String, String> annotations,
String dockerImage, String cpu, String memory, List<ContainerPort> ports,
List<EnvVar> environmentVariables, List<String> imagePullSecrets, String imagePullPolicy)
throws KubernetesClientException;
开发者ID:apache,项目名称:stratos,代码行数:21,代码来源:KubernetesAPIClientInterface.java
注:本文中的io.fabric8.kubernetes.api.model.ContainerPort类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论