Assign Extended Resources to a Container
Kubernetes Docs · نسخهٔ f284a9e7c87f · CC BY 4.0 برای مستندات و مجوزهای همراه
<!-- overview -->
{{< feature-state state="stable" >}}
This page shows how to assign extended resources to a Container.
{{% heading "prerequisites" %}}
{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
Before you do this exercise, do the exercise in Advertise Extended Resources for a Node. That will configure one of your Nodes to advertise a dongle resource.
<!-- steps -->
Assign an extended resource to a Pod
To request an extended resource, include the resources.requests.<resource_name> field in the container manifest. *.kubernetes.io/. Valid extended resource names have the form example.com/foo where example.com is replaced with your organization's domain and foo is a descriptive resource name.
Here is the configuration file for a Pod that has one Container:
{{% code_sample file="pods/resource/extended-resource-pod.yaml" %}}
In the configuration file, you can see that the Container requests 3 dongles.
Create a Pod:
kubectl apply -f https://k8s.io/examples/pods/resource/extended-resource-pod.yamlVerify that the Pod is running:
kubectl get pod extended-resource-demoDescribe the Pod:
kubectl describe pod extended-resource-demoThe output shows dongle requests:
Limits:
example.com/dongle: 3
Requests:
example.com/dongle: 3Attempt to create a second Pod
Here is the configuration file for a Pod that has one Container. The Container requests two dongles.
{{% code_sample file="pods/resource/extended-resource-pod-2.yaml" %}}
Kubernetes will not be able to satisfy the request for two dongles, because the first Pod used three of the four available dongles.
Attempt to create a Pod:
kubectl apply -f https://k8s.io/examples/pods/resource/extended-resource-pod-2.yamlDescribe the Pod
kubectl describe pod extended-resource-demo-2The output shows that the Pod cannot be scheduled, because there is no Node that has 2 dongles available:
Conditions:
Type Status
PodScheduled False
...
Events:
...
... Warning FailedScheduling pod (extended-resource-demo-2) failed to fit in any node
fit failure summary on nodes : Insufficient example.com/dongle (1)View the Pod status:
kubectl get pod extended-resource-demo-2The output shows that the Pod was created, but not scheduled to run on a Node. It has a status of Pending:
NAME READY STATUS RESTARTS AGE
extended-resource-demo-2 0/1 Pending 0 6mClean up
Delete the Pods that you created for this exercise:
kubectl delete pod extended-resource-demo
kubectl delete pod extended-resource-demo-2Extended resources backed by DRA
{{< feature-state feature_gate_name="DRAExtendedResource" >}}
The exercise above uses an extended resource that a Node advertises. Extended resources can also be backed by {{< glossary_tooltip text="Dynamic Resource Allocation" term_id="dra" >}} (DRA): a DeviceClass sets an extendedResourceName, and the scheduler satisfies matching extended-resource requests using DRA devices instead of Node-advertised capacity.
A Pod requests the resource the same way in both cases — through resources.requests.<resource_name> — so a workload does not need to know whether a device plugin or DRA provides it. The same resource name can even be provided by a device plugin on some Nodes and by DRA on others.
For the DeviceClass setup and examples, see Extended resource allocation by DRA.
{{% heading "whatsnext" %}}
For application developers
- Assign Memory Resources to Containers and Pods
- Assign CPU Resources to Containers and Pods
For cluster administrators
- Advertise Extended Resources for a Node