<p>The fabric8 kubernetes Java &amp; Scala client API is great for talking to kubernetes (or OpenShift), but its documentation is very sparse.  What is a code example for adding resource requirements to containers running in a kubernetes pod?</p>

<p>If you are using the fabric8 kubernetes-client API for Java and Scala, here is a snippet of code that demonstrates how to add resource requirements to a container running in a pod.  This code was copied from Scala, but Java code would be very similar:</p>

<pre><code>// other fabric8 imports not included; just focusing on resource
// requirements logic in this example
import io.fabric8.kubernetes.api.model.Quantity
import io.fabric8.kubernetes.api.model.ResourceRequirementsBuilder

// Use Java style Map (as opposed to Scala's Map class)
val reqMap: java.util.Map[String, Quantity] =
  new java.util.HashMap[String, Quantity]()

// add CPU and memory requirements to the map
reqMap.put("cpu", new Quantity("1"))
reqMap.put("memory", new Quantity("1500Mi"))

// Build a ResourceRequirements object from the map
val reqs = new ResourceRequirementsBuilder()
  .withRequests(reqMap)
  .build()

// pass the ResourceRequirements object to the container spec
val pod = new PodBuilder()
  .withNewMetadata()
  .withName(podName)
  .endMetadata()
  .withNewSpec()
  .withRestartPolicy("OnFailure")
  .addNewContainer()
  .withName(containerName)
  .withImage(containerImage)
  .withImagePullPolicy("Always")
  .withResources(reqs)            // &lt;-- resource reqs here
  .withCommand(commandName)
  .withArgs(commandArguments)
  .endContainer()
  .endSpec()
  .build()

// create the new pod with resource requirements via the 
// fabric8 kube client:
client.pods().inNamespace(nameSpace).withName(podName).create(pod)
</code></pre>
