Skip to main content

pod_spec_from_resources

Constructs a Kubernetes V1PodSpec object from specified resource requests and limits. It maps generic resource definitions (CPU, memory, GPU, ephemeral storage) to Kubernetes-specific resource requirements for a primary container.

def pod_spec_from_resources(
primary_container_name: str = _PRIMARY_CONTAINER_DEFAULT_NAME,
requests: Optional[Resources] = None,
limits: Optional[Resources] = None,
k8s_gpu_resource_key: str = "nvidia.com/gpu"
) - > V1PodSpec

Constructs a Kubernetes V1PodSpec object from the provided resource requests and limits. This function is used to define the resource requirements for a primary container within a pod.

Parameters

NameTypeDescription
primary_container_namestr = _PRIMARY_CONTAINER_DEFAULT_NAMEThe name to assign to the primary container within the V1PodSpec. This name identifies the main application container.
requestsOptional[Resources] = NoneThe resource requests for the primary container. These values specify the minimum resources guaranteed to the container.
limitsOptional[Resources] = NoneThe resource limits for the primary container. These values specify the maximum resources the container can consume.
k8s_gpu_resource_keystr = "nvidia.com/gpu"The Kubernetes resource key used to identify GPU resources. This allows for custom GPU resource naming in Kubernetes clusters.

Returns

TypeDescription
V1PodSpecA Kubernetes V1PodSpec object configured with the specified resource requests and limits for a single primary container.