Assign Extended Resources to a Container

FEATURE STATE: Kubernetes v1.27 [stable]

This page shows how to assign extended resources to a Container.

Before you begin

You need to have a Kubernetes cluster, and the kubectl command-line tool must be configured to communicate with your cluster. It is recommended to run this tutorial on a cluster with at least two nodes that are not acting as control plane hosts. If you do not already have a cluster, you can create one by using minikube or you can use one of these Kubernetes playgrounds:

To check the version, enter kubectl version.

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.

Assign an extended resource to a Pod

To request an extended resource, include the resources:requests field in your Container manifest. Extended resources are fully qualified with any domain outside of *.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:

pods/resource/extended-resource-pod.yaml Assign Extended Resources to a Container - 图1

  1. apiVersion: v1
  2. kind: Pod
  3. metadata:
  4. name: extended-resource-demo
  5. spec:
  6. containers:
  7. - name: extended-resource-demo-ctr
  8. image: nginx
  9. resources:
  10. requests:
  11. example.com/dongle: 3
  12. limits:
  13. example.com/dongle: 3

In the configuration file, you can see that the Container requests 3 dongles.

Create a Pod:

  1. kubectl apply -f https://k8s.io/examples/pods/resource/extended-resource-pod.yaml

Verify that the Pod is running:

  1. kubectl get pod extended-resource-demo

Describe the Pod:

  1. kubectl describe pod extended-resource-demo

The output shows dongle requests:

  1. Limits:
  2. example.com/dongle: 3
  3. Requests:
  4. example.com/dongle: 3

Attempt to create a second Pod

Here is the configuration file for a Pod that has one Container. The Container requests two dongles.

pods/resource/extended-resource-pod-2.yaml Assign Extended Resources to a Container - 图2

  1. apiVersion: v1
  2. kind: Pod
  3. metadata:
  4. name: extended-resource-demo-2
  5. spec:
  6. containers:
  7. - name: extended-resource-demo-2-ctr
  8. image: nginx
  9. resources:
  10. requests:
  11. example.com/dongle: 2
  12. limits:
  13. example.com/dongle: 2

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:

  1. kubectl apply -f https://k8s.io/examples/pods/resource/extended-resource-pod-2.yaml

Describe the Pod

  1. kubectl describe pod extended-resource-demo-2

The output shows that the Pod cannot be scheduled, because there is no Node that has 2 dongles available:

  1. Conditions:
  2. Type Status
  3. PodScheduled False
  4. ...
  5. Events:
  6. ...
  7. ... Warning FailedScheduling pod (extended-resource-demo-2) failed to fit in any node
  8. fit failure summary on nodes : Insufficient example.com/dongle (1)

View the Pod status:

  1. kubectl get pod extended-resource-demo-2

The output shows that the Pod was created, but not scheduled to run on a Node. It has a status of Pending:

  1. NAME READY STATUS RESTARTS AGE
  2. extended-resource-demo-2 0/1 Pending 0 6m

Clean up

Delete the Pods that you created for this exercise:

  1. kubectl delete pod extended-resource-demo
  2. kubectl delete pod extended-resource-demo-2

What’s next

For application developers

For cluster administrators