io.kubernetes.client.openapi.models.V1Container Java Examples

The following examples show how to use io.kubernetes.client.openapi.models.V1Container. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PodLogsTest.java    From java with Apache License 2.0 5 votes vote down vote up
@Test
public void testStream() throws ApiException, IOException {
  V1Pod pod =
      new V1Pod()
          .metadata(new V1ObjectMeta().name(podName).namespace(namespace))
          .spec(
              new V1PodSpec()
                  .containers(Arrays.asList(new V1Container().name(container).image("nginx"))));

  String content = "this is some\n content for \n various logs \n done";

  stubFor(
      get(urlPathEqualTo("/api/v1/namespaces/" + namespace + "/pods/" + podName + "/log"))
          .willReturn(
              aResponse()
                  .withStatus(200)
                  .withHeader("Content-Type", "text/plain")
                  .withBody(content)));

  PodLogs logs = new PodLogs(client);
  InputStream is = logs.streamNamespacedPodLog(pod);

  verify(
      getRequestedFor(
              urlPathEqualTo("/api/v1/namespaces/" + namespace + "/pods/" + podName + "/log"))
          .withQueryParam("container", equalTo(container))
          .withQueryParam("follow", equalTo("true"))
          .withQueryParam("pretty", equalTo("false"))
          .withQueryParam("previous", equalTo("false"))
          .withQueryParam("timestamps", equalTo("false")));

  ByteArrayOutputStream bos = new ByteArrayOutputStream();
  ByteStreams.copy(is, bos);
  assertEquals(content, bos.toString());
}
 
Example #2
Source File: AppsV1Controller.java    From incubator-heron with Apache License 2.0 5 votes vote down vote up
private void mountVolumeIfPresent(V1Container container) {
  final Config config = getConfiguration();
  if (KubernetesContext.hasContainerVolume(config)) {
    final V1VolumeMount mount =
        new V1VolumeMount()
            .name(KubernetesContext.getContainerVolumeName(config))
            .mountPath(KubernetesContext.getContainerVolumeMountPath(config));
    container.volumeMounts(Collections.singletonList(mount));
  }
}
 
Example #3
Source File: ZookeeperK8sService.java    From pravega with Apache License 2.0 5 votes vote down vote up
private V1Deployment getDeployment() {
    V1Container container = new V1ContainerBuilder().withName("zookeeper-operator")
                                                    .withImage(ZOOKEEPER_OPERATOR_IMAGE)
                                                    .withPorts(new V1ContainerPortBuilder().withContainerPort(60000).build())
                                                    .withCommand("zookeeper-operator")
                                                    .withImagePullPolicy(IMAGE_PULL_POLICY)
                                                    .withEnv(new V1EnvVarBuilder().withName("WATCH_NAMESPACE")
                                                                                  .withValueFrom(new V1EnvVarSourceBuilder()
                                                                                                         .withFieldRef(new V1ObjectFieldSelectorBuilder()
                                                                                                                               .withFieldPath("metadata.namespace")
                                                                                                                               .build()).build()).build(),
                                                             new V1EnvVarBuilder().withName("OPERATOR_NAME")
                                                                                  .withValueFrom(new V1EnvVarSourceBuilder()
                                                                                                         .withFieldRef(new V1ObjectFieldSelectorBuilder()
                                                                                                                               .withFieldPath("metadata.name")
                                                                                                                               .build()).build()).build())
                                                    .build();
    return new V1DeploymentBuilder().withMetadata(new V1ObjectMetaBuilder().withName("zookeeper-operator")
                                                                           .withNamespace(NAMESPACE)
                                                                           .build())
                                    .withKind("Deployment")
                                    .withApiVersion("apps/v1")
                                    .withSpec(new V1DeploymentSpecBuilder().withMinReadySeconds(MIN_READY_SECONDS)
                                                                           .withSelector(new V1LabelSelectorBuilder()
                                                                                                 .withMatchLabels(ImmutableMap.of("name", "zookeeper-operator"))
                                                                                                 .build())
                                                                           .withTemplate(new V1PodTemplateSpecBuilder()
                                                                                                 .withMetadata(new V1ObjectMetaBuilder()
                                                                                                                       .withLabels(ImmutableMap.of("name", "zookeeper-operator"))
                                                                                                                       .build())
                                                                                                 .withSpec(new V1PodSpecBuilder()
                                                                                                                   .withContainers(container)
                                                                                                                   .build()).build()).build())
                                    .build();
}
 
Example #4
Source File: AbstractService.java    From pravega with Apache License 2.0 5 votes vote down vote up
private V1Deployment getPravegaOperatorDeployment() {
    V1Container container = new V1ContainerBuilder().withName(PRAVEGA_OPERATOR)
                                                    .withImage(PRAVEGA_OPERATOR_IMAGE)
                                                    .withPorts(new V1ContainerPortBuilder().withContainerPort(60000).build())
                                                    .withCommand(PRAVEGA_OPERATOR)
                                                    // start the pravega-operator in test mode to disable minimum replica count check.
                                                    .withArgs("-test")
                                                    .withImagePullPolicy(IMAGE_PULL_POLICY)
                                                    .withEnv(new V1EnvVarBuilder().withName("WATCH_NAMESPACE")
                                                                                  .withValueFrom(new V1EnvVarSourceBuilder()
                                                                                                         .withFieldRef(new V1ObjectFieldSelectorBuilder()
                                                                                                                               .withFieldPath("metadata.namespace")
                                                                                                                               .build())
                                                                                                         .build())
                                                                                  .build(),
                                                             new V1EnvVarBuilder().withName("OPERATOR_NAME")
                                                                                  .withValue(PRAVEGA_OPERATOR)
                                                                                  .build())
                                                    .build();
    return new V1DeploymentBuilder().withMetadata(new V1ObjectMetaBuilder().withName(PRAVEGA_OPERATOR)
                                                                           .withNamespace(NAMESPACE)
                                                                           .build())
                                    .withKind("Deployment")
                                    .withApiVersion("apps/v1")
                                    .withSpec(new V1DeploymentSpecBuilder().withMinReadySeconds(MIN_READY_SECONDS)
                                                                           .withReplicas(1)
                                                                           .withSelector(new V1LabelSelectorBuilder()
                                                                                                 .withMatchLabels(ImmutableMap.of("name", PRAVEGA_OPERATOR))
                                                                                                 .build())
                                                                           .withTemplate(new V1PodTemplateSpecBuilder()
                                                                                                 .withMetadata(new V1ObjectMetaBuilder()
                                                                                                                       .withLabels(ImmutableMap.of("name", PRAVEGA_OPERATOR))
                                                                                                                       .build())
                                                                                                 .withSpec(new V1PodSpecBuilder()
                                                                                                                   .withContainers(container)
                                                                                                                   .build())
                                                                                                 .build())
                                                                           .build())
                                    .build();
}
 
Example #5
Source File: DefaultTaskToPodConverter.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
@Override
public V1Pod apply(Job<?> job, Task task) {
    String taskId = task.getId();
    TitanProtos.ContainerInfo containerInfo = buildContainerInfo(job, task);
    Map<String, String> annotations = KubeUtil.createPodAnnotations(job, task, containerInfo.toByteArray(),
            containerInfo.getPassthroughAttributesMap(), configuration.isJobDescriptorAnnotationEnabled());

    V1ObjectMeta metadata = new V1ObjectMeta()
            .name(taskId)
            .annotations(annotations)
            .labels(ImmutableMap.of(
                    KubeConstants.POD_LABEL_JOB_ID, job.getId(),
                    KubeConstants.POD_LABEL_TASK_ID, taskId
            ));

    V1Container container = new V1Container()
            .name(taskId)
            .image("imageIsInContainerInfo")
            .resources(buildV1ResourceRequirements(job.getJobDescriptor().getContainer().getContainerResources()));

    V1PodSpec spec = new V1PodSpec()
            .schedulerName(configuration.getKubeSchedulerName())
            .containers(Collections.singletonList(container))
            .terminationGracePeriodSeconds(POD_TERMINATION_GRACE_PERIOD_SECONDS)
            .restartPolicy(NEVER_RESTART_POLICY)
            .affinity(podAffinityFactory.buildV1Affinity(job, task))
            .tolerations(taintTolerationFactory.buildV1Toleration(job, task))
            .topologySpreadConstraints(buildTopologySpreadConstraints(job));

    return new V1Pod().metadata(metadata).spec(spec);
}
 
Example #6
Source File: KubeApiServerIntegrator.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
private V1Pod taskInfoToPod(TaskInfoRequest taskInfoRequest) {
    Protos.TaskInfo taskInfo = taskInfoRequest.getTaskInfo();
    String taskId = taskInfo.getName();
    String nodeName = taskInfo.getSlaveId().getValue();
    Map<String, String> annotations = KubeUtil.createPodAnnotations(taskInfoRequest.getJob(), taskInfoRequest.getTask(),
            taskInfo.getData().toByteArray(), taskInfoRequest.getPassthroughAttributes(),
            mesosConfiguration.isJobDescriptorAnnotationEnabled());

    V1ObjectMeta metadata = new V1ObjectMeta()
            .name(taskId)
            .annotations(annotations);

    V1Container container = new V1Container()
            .name(taskId)
            .image("imageIsInContainerInfo")
            .resources(taskInfoToResources(taskInfo));

    V1PodSpec spec = new V1PodSpec()
            .nodeName(nodeName)
            .containers(Collections.singletonList(container))
            .terminationGracePeriodSeconds(directKubeConfiguration.getPodTerminationGracePeriodSeconds())
            .restartPolicy(NEVER_RESTART_POLICY);

    return new V1Pod()
            .metadata(metadata)
            .spec(spec);
}
 
Example #7
Source File: FluentExample.java    From java with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws IOException, ApiException {
  ApiClient client = Config.defaultClient();
  Configuration.setDefaultApiClient(client);

  CoreV1Api api = new CoreV1Api();

  V1Pod pod =
      new V1PodBuilder()
          .withNewMetadata()
          .withName("apod")
          .endMetadata()
          .withNewSpec()
          .addNewContainer()
          .withName("www")
          .withImage("nginx")
          .endContainer()
          .endSpec()
          .build();

  api.createNamespacedPod("default", pod, null, null, null);

  V1Pod pod2 =
      new V1Pod()
          .metadata(new V1ObjectMeta().name("anotherpod"))
          .spec(
              new V1PodSpec()
                  .containers(Arrays.asList(new V1Container().name("www").image("nginx"))));

  api.createNamespacedPod("default", pod2, null, null, null);

  V1PodList list =
      api.listNamespacedPod("default", null, null, null, null, null, null, null, null, null);
  for (V1Pod item : list.getItems()) {
    System.out.println(item.getMetadata().getName());
  }
}
 
Example #8
Source File: PodLogsTest.java    From java with Apache License 2.0 5 votes vote down vote up
@Test
public void testNotFound() throws ApiException, IOException {
  V1Pod pod =
      new V1Pod()
          .metadata(new V1ObjectMeta().name(podName).namespace(namespace))
          .spec(
              new V1PodSpec()
                  .containers(Arrays.asList(new V1Container().name(container).image("nginx"))));

  stubFor(
      get(urlPathEqualTo("/api/v1/namespaces/" + namespace + "/pods/" + podName + "/log"))
          .willReturn(
              aResponse()
                  .withStatus(404)
                  .withHeader("Content-Type", "text/plain")
                  .withBody("Not Found")));

  PodLogs logs = new PodLogs(client);
  boolean thrown = false;
  try {
    logs.streamNamespacedPodLog(pod);
  } catch (ApiException ex) {
    assertEquals(404, ex.getCode());
    thrown = true;
  }
  assertEquals(thrown, true);
  verify(
      getRequestedFor(
              urlPathEqualTo("/api/v1/namespaces/" + namespace + "/pods/" + podName + "/log"))
          .withQueryParam("container", equalTo(container))
          .withQueryParam("follow", equalTo("true"))
          .withQueryParam("pretty", equalTo("false"))
          .withQueryParam("previous", equalTo("false"))
          .withQueryParam("timestamps", equalTo("false")));
}
 
Example #9
Source File: V1PodSpec.java    From java with Apache License 2.0 5 votes vote down vote up
/**
 * List of initialization containers belonging to the pod. Init containers are executed in order prior to containers being started. If any init container fails, the pod is considered to have failed and is handled according to its restartPolicy. The name for an init container or normal container must be unique among all containers. Init containers may not have Lifecycle actions, Readiness probes, Liveness probes, or Startup probes. The resourceRequirements of an init container are taken into account during scheduling by finding the highest request/limit for each resource type, and then using the max of of that value or the sum of the normal containers. Limits are applied to init containers in a similar fashion. Init containers cannot currently be added or removed. Cannot be updated. More info: https://kubernetes.io/docs/concepts/workloads/pods/init-containers/
 * @return initContainers
**/
@javax.annotation.Nullable
@ApiModelProperty(value = "List of initialization containers belonging to the pod. Init containers are executed in order prior to containers being started. If any init container fails, the pod is considered to have failed and is handled according to its restartPolicy. The name for an init container or normal container must be unique among all containers. Init containers may not have Lifecycle actions, Readiness probes, Liveness probes, or Startup probes. The resourceRequirements of an init container are taken into account during scheduling by finding the highest request/limit for each resource type, and then using the max of of that value or the sum of the normal containers. Limits are applied to init containers in a similar fashion. Init containers cannot currently be added or removed. Cannot be updated. More info: https://kubernetes.io/docs/concepts/workloads/pods/init-containers/")

public List<V1Container> getInitContainers() {
  return initContainers;
}
 
Example #10
Source File: V1PodSpec.java    From java with Apache License 2.0 5 votes vote down vote up
public V1PodSpec addInitContainersItem(V1Container initContainersItem) {
  if (this.initContainers == null) {
    this.initContainers = new ArrayList<V1Container>();
  }
  this.initContainers.add(initContainersItem);
  return this;
}
 
Example #11
Source File: GenericClientExample.java    From java with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {

    // The following codes demonstrates using generic client to manipulate pods
    V1Pod pod =
        new V1Pod()
            .metadata(new V1ObjectMeta().name("foo").namespace("default"))
            .spec(
                new V1PodSpec()
                    .containers(Arrays.asList(new V1Container().name("c").image("test"))));
    ApiClient apiClient = ClientBuilder.standard().build();
    GenericKubernetesApi<V1Pod, V1PodList> podClient =
        new GenericKubernetesApi<>(V1Pod.class, V1PodList.class, "", "v1", "pods", apiClient);

    KubernetesApiResponse<V1Pod> createResponse = podClient.create(pod);
    if (!createResponse.isSuccess()) {
      throw new RuntimeException(createResponse.getStatus().toString());
    }
    System.out.println("Created!");

    KubernetesApiResponse<V1Pod> patchResponse =
        podClient.patch(
            "default",
            "foo",
            V1Patch.PATCH_FORMAT_STRATEGIC_MERGE_PATCH,
            new V1Patch("{\"metadata\":{\"finalizers\":[\"example.io/foo\"]}}"));
    if (!patchResponse.isSuccess()) {
      throw new RuntimeException(patchResponse.getStatus().toString());
    }
    System.out.println("Patched!");

    KubernetesApiResponse<V1Pod> deleteResponse = podClient.delete("default", "foo");
    if (!deleteResponse.isSuccess()) {
      throw new RuntimeException(deleteResponse.getStatus().toString());
    }
    if (deleteResponse.getObject() != null) {
      System.out.println(
          "Received after-deletion status of the requested object, will be deleting in background!");
    }
    System.out.println("Deleted!");
  }
 
Example #12
Source File: V1PodSpec.java    From java with Apache License 2.0 4 votes vote down vote up
public void setInitContainers(List<V1Container> initContainers) {
  this.initContainers = initContainers;
}
 
Example #13
Source File: JobMasterRequestObject.java    From twister2 with Apache License 2.0 4 votes vote down vote up
/**
 * construct pod template
 */
public static V1PodTemplateSpec constructPodTemplate() {

  V1PodTemplateSpec template = new V1PodTemplateSpec();
  V1ObjectMeta templateMetaData = new V1ObjectMeta();
  HashMap<String, String> labels = KubernetesUtils.createJobLabels(jobID);
  labels.put("t2-mp", jobID); // job master pod

  templateMetaData.setLabels(labels);
  template.setMetadata(templateMetaData);

  V1PodSpec podSpec = new V1PodSpec();
  podSpec.setTerminationGracePeriodSeconds(0L);

  ArrayList<V1Volume> volumes = new ArrayList<>();
  V1Volume memoryVolume = new V1Volume();
  memoryVolume.setName(KubernetesConstants.POD_MEMORY_VOLUME_NAME);
  V1EmptyDirVolumeSource volumeSource1 = new V1EmptyDirVolumeSource();
  volumeSource1.setMedium("Memory");
  memoryVolume.setEmptyDir(volumeSource1);
  volumes.add(memoryVolume);

  // a volatile disk based volume
  // create it if the requested disk space is positive
  if (JobMasterContext.volatileVolumeRequested(config)) {
    double vSize = JobMasterContext.volatileVolumeSize(config);
    V1Volume volatileVolume = RequestObjectBuilder.createVolatileVolume(vSize);
    volumes.add(volatileVolume);
  }

  if (JobMasterContext.persistentVolumeRequested(config)) {
    String claimName = jobID;
    V1Volume persistentVolume = RequestObjectBuilder.createPersistentVolume(claimName);
    volumes.add(persistentVolume);
  }

  podSpec.setVolumes(volumes);

  ArrayList<V1Container> containers = new ArrayList<V1Container>();
  containers.add(constructContainer());
  podSpec.setContainers(containers);

  template.setSpec(podSpec);
  return template;
}
 
Example #14
Source File: JobMasterRequestObject.java    From twister2 with Apache License 2.0 4 votes vote down vote up
/**
 * construct a container
 */
public static V1Container constructContainer() {
  // construct container and add it to podSpec
  V1Container container = new V1Container();
  container.setName("twister2-job-master-0");

  String containerImage = KubernetesContext.twister2DockerImageForK8s(config);
  if (containerImage == null) {
    throw new RuntimeException("Container Image name is null. Config parameter: "
        + "twister2.resource.kubernetes.docker.image can not be null");
  }
  container.setImage(containerImage);
  container.setImagePullPolicy(KubernetesContext.imagePullPolicy(config));
  container.setCommand(Arrays.asList("/bin/bash"));
  container.setArgs(Arrays.asList("-c", "./init.sh"));

  int jmRam = JobMasterContext.jobMasterRAM(config) + 128;
  V1ResourceRequirements resReq = new V1ResourceRequirements();
  resReq.putRequestsItem("cpu", new Quantity(JobMasterContext.jobMasterCpu(config) + ""));
  resReq.putRequestsItem("memory", new Quantity(jmRam + "Mi"));
  container.setResources(resReq);

  ArrayList<V1VolumeMount> volumeMounts = new ArrayList<>();
  V1VolumeMount memoryVolumeMount = new V1VolumeMount();
  memoryVolumeMount.setName(KubernetesConstants.POD_MEMORY_VOLUME_NAME);
  memoryVolumeMount.setMountPath(KubernetesConstants.POD_MEMORY_VOLUME);
  volumeMounts.add(memoryVolumeMount);

  if (JobMasterContext.volatileVolumeRequested(config)) {
    V1VolumeMount volatileVolumeMount = new V1VolumeMount();
    volatileVolumeMount.setName(KubernetesConstants.POD_VOLATILE_VOLUME_NAME);
    volatileVolumeMount.setMountPath(KubernetesConstants.POD_VOLATILE_VOLUME);
    volumeMounts.add(volatileVolumeMount);
  }

  if (JobMasterContext.persistentVolumeRequested(config)) {
    V1VolumeMount persVolumeMount = new V1VolumeMount();
    persVolumeMount.setName(KubernetesConstants.PERSISTENT_VOLUME_NAME);
    persVolumeMount.setMountPath(KubernetesConstants.PERSISTENT_VOLUME_MOUNT);
    volumeMounts.add(persVolumeMount);
  }

  container.setVolumeMounts(volumeMounts);

  V1ContainerPort port = new V1ContainerPort();
  port.name("job-master-port");
  port.containerPort(JobMasterContext.jobMasterPort(config));
  port.setProtocol("TCP");
  container.setPorts(Arrays.asList(port));

  container.setEnv(constructEnvironmentVariables(JobMasterContext.jobMasterRAM(config)));

  return container;
}
 
Example #15
Source File: RequestObjectBuilder.java    From twister2 with Apache License 2.0 4 votes vote down vote up
/**
 * construct pod template
 */
public static V1PodTemplateSpec constructPodTemplate(ComputeResource computeResource) {

  V1PodTemplateSpec template = new V1PodTemplateSpec();
  V1ObjectMeta templateMetaData = new V1ObjectMeta();
  HashMap<String, String> labels = KubernetesUtils.createJobLabels(jobID);
  labels.put("t2-wp", jobID); // worker pod

  templateMetaData.setLabels(labels);
  template.setMetadata(templateMetaData);

  V1PodSpec podSpec = new V1PodSpec();
  podSpec.setTerminationGracePeriodSeconds(0L);

  ArrayList<V1Volume> volumes = new ArrayList<>();
  V1Volume memoryVolume = new V1Volume();
  memoryVolume.setName(KubernetesConstants.POD_MEMORY_VOLUME_NAME);
  V1EmptyDirVolumeSource volumeSource1 = new V1EmptyDirVolumeSource();
  volumeSource1.setMedium("Memory");
  memoryVolume.setEmptyDir(volumeSource1);
  volumes.add(memoryVolume);

  // a volatile disk based volume
  // create it if the requested disk space is positive
  if (computeResource.getDiskGigaBytes() > 0) {
    double volumeSize = computeResource.getDiskGigaBytes() * computeResource.getWorkersPerPod();
    V1Volume volatileVolume = createVolatileVolume(volumeSize);
    volumes.add(volatileVolume);
  }

  if (SchedulerContext.persistentVolumeRequested(config)) {
    String claimName = jobID;
    V1Volume persistentVolume = createPersistentVolume(claimName);
    volumes.add(persistentVolume);
  }

  // if openmpi is used, we initialize a Secret volume on each pod
  if (SchedulerContext.useOpenMPI(config)) {
    String secretName = KubernetesContext.secretName(config);
    V1Volume secretVolume = createSecretVolume(secretName);
    volumes.add(secretVolume);
  }

  podSpec.setVolumes(volumes);

  int containersPerPod = computeResource.getWorkersPerPod();

  // if openmpi is used, we initialize only one container for each pod
  if (SchedulerContext.useOpenMPI(config)) {
    containersPerPod = 1;
  }

  ArrayList<V1Container> containers = new ArrayList<V1Container>();
  for (int i = 0; i < containersPerPod; i++) {
    containers.add(constructContainer(computeResource, i));
  }
  podSpec.setContainers(containers);

  if (computeResource.getIndex() == 0) {
    constructAffinity(podSpec);
  }

  template.setSpec(podSpec);

  return template;
}
 
Example #16
Source File: V1PodSpec.java    From java with Apache License 2.0 4 votes vote down vote up
public void setContainers(List<V1Container> containers) {
  this.containers = containers;
}
 
Example #17
Source File: V1PodSpec.java    From java with Apache License 2.0 4 votes vote down vote up
/**
 * List of containers belonging to the pod. Containers cannot currently be added or removed. There must be at least one container in a Pod. Cannot be updated.
 * @return containers
**/
@ApiModelProperty(required = true, value = "List of containers belonging to the pod. Containers cannot currently be added or removed. There must be at least one container in a Pod. Cannot be updated.")

public List<V1Container> getContainers() {
  return containers;
}
 
Example #18
Source File: V1PodSpec.java    From java with Apache License 2.0 4 votes vote down vote up
public V1PodSpec addContainersItem(V1Container containersItem) {
  this.containers.add(containersItem);
  return this;
}
 
Example #19
Source File: AppsV1Controller.java    From incubator-heron with Apache License 2.0 4 votes vote down vote up
private V1Container getContainer(List<String> executorCommand, Resource resource,
    int numberOfInstances) {
  final Config configuration = getConfiguration();
  final V1Container container = new V1Container().name("executor");

  // set up the container images
  container.setImage(KubernetesContext.getExecutorDockerImage(configuration));

  // set up the container command
  container.setCommand(executorCommand);

  if (KubernetesContext.hasImagePullPolicy(configuration)) {
    container.setImagePullPolicy(KubernetesContext.getKubernetesImagePullPolicy(configuration));
  }

  // setup the environment variables for the container
  final V1EnvVar envVarHost = new V1EnvVar();
  envVarHost.name(KubernetesConstants.ENV_HOST)
      .valueFrom(new V1EnvVarSource()
          .fieldRef(new V1ObjectFieldSelector()
              .fieldPath(KubernetesConstants.POD_IP)));

  final V1EnvVar envVarPodName = new V1EnvVar();
  envVarPodName.name(KubernetesConstants.ENV_POD_NAME)
      .valueFrom(new V1EnvVarSource()
          .fieldRef(new V1ObjectFieldSelector()
              .fieldPath(KubernetesConstants.POD_NAME)));
  container.setEnv(Arrays.asList(envVarHost, envVarPodName));


  // set container resources
  final V1ResourceRequirements resourceRequirements = new V1ResourceRequirements();
  final Map<String, Quantity> requests = new HashMap<>();
  requests.put(KubernetesConstants.MEMORY,
      Quantity.fromString(KubernetesUtils.Megabytes(resource.getRam())));
  requests.put(KubernetesConstants.CPU,
       Quantity.fromString(Double.toString(roundDecimal(resource.getCpu(), 3))));
  resourceRequirements.setRequests(requests);
  container.setResources(resourceRequirements);

  // set container ports
  final boolean debuggingEnabled =
      TopologyUtils.getTopologyRemoteDebuggingEnabled(
          Runtime.topology(getRuntimeConfiguration()));
  container.setPorts(getContainerPorts(debuggingEnabled, numberOfInstances));

  // setup volume mounts
  mountVolumeIfPresent(container);

  return container;
}