Tasks

Step-by-step instructions for performing operations with Kubernetes.

Documentation for Kubernetes v1.7 is no longer actively maintained. The version you are currently viewing is a static snapshot. For up-to-date documentation, see the latest version.

Edit This Page

Assign Opaque Integer Resources to a Container

This page shows how to assign opaque integer resources to a Container.

FEATURE STATE: Kubernetes v1.7 alpha

This feature is currently in a alpha state, meaning:

  • The version names contain alpha (e.g. v1alpha1).
  • Might be buggy. Enabling the feature may expose bugs. Disabled by default.
  • Support for feature may be dropped at any time without notice.
  • The API may change in incompatible ways in a later software release without notice.
  • Recommended for use only in short-lived testing clusters, due to increased risk of bugs and lack of long-term support.

Before you begin

You need to have a Kubernetes cluster, and the kubectl command-line tool must be configured to communicate with your cluster. If you do not already have a cluster, you can create one by using Minikube, or you can use one of these Kubernetes playgrounds:

Before you do this exercise, do the exercise in Advertise Opaque Integer Resources for a Node. That will configure one of your Nodes to advertise a dongle resource.

Assign an opaque integer resource to a Pod

To request an opaque integer resource, include the resources:requests field in your Container manifest. Opaque integer resources have the prefix pod.alpha.kubernetes.io/opaque-int-resource-.

Here is the configuration file for a Pod that has one Container:

oir-pod.yaml
apiVersion: v1
kind: Pod
metadata:
  name: oir-demo
spec:
  containers:
  - name: oir-demo-ctr
    image: nginx
    resources:
      requests:
        pod.alpha.kubernetes.io/opaque-int-resource-dongle: 3

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

Create a Pod:

kubectl create -f https://k8s.io/docs/tasks/configure-pod-container/oir-pod.yaml

Verify that the Pod is running:

kubectl get pod oir-demo

Describe the Pod:

kubectl describe pod oir-demo

The output shows dongle requests:

Requests:
  pod.alpha.kubernetes.io/opaque-int-resource-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.

oir-pod-2.yaml
apiVersion: v1
kind: Pod
metadata:
  name: oir-demo-2
spec:
  containers:
  - name: oir-demo-2-ctr
    image: nginx
    resources:
      requests:
        pod.alpha.kubernetes.io/opaque-int-resource-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:

kubectl create -f https://k8s.io/docs/tasks/configure-pod-container/oir-pod-2.yaml

Describe the Pod

kubectl describe pod oir-demo-2

The 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 (oir-demo-2) failed to fit in any node
fit failure summary on nodes : Insufficient pod.alpha.kubernetes.io/opaque-int-resource-dongle (1)

View the Pod status:

kubectl get pod oir-demo-2

The 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
oir-demo-2   0/1       Pending   0          6m

Clean up

Delete the Pod that you created for this exercise:

kubectl delete pod oir-demo

What’s next

For application developers

For cluster administrators

Analytics

Create an Issue Edit this Page