Advertise Extended Resources for a Node

    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 or you can use one of these Kubernetes playgrounds:

    To check the version, enter .

    Get the names of your Nodes

    Choose one of your Nodes to use for this exercise.

    To advertise a new extended resource on a Node, send an HTTP PATCH request to the Kubernetes API server. For example, suppose one of your Nodes has four dongles attached. Here’s an example of a PATCH request that advertises four dongle resources for your Node.

    1. PATCH /api/v1/nodes/<your-node-name>/status HTTP/1.1
    2. Accept: application/json
    3. Content-Type: application/json-patch+json
    4. Host: k8s-master:8080
    5. [
    6. "op": "add",
    7. "path": "/status/capacity/example.com~1dongle",
    8. "value": "4"
    9. }
    10. ]

    Note that Kubernetes does not need to know what a dongle is or what a dongle is for. The preceding PATCH request tells Kubernetes that your Node has four things that you call dongles.

    Start a proxy, so that you can easily send requests to the Kubernetes API server:

    1. kubectl proxy
    1. --request PATCH \
    2. --data '[{"op": "add", "path": "/status/capacity/example.com~1dongle", "value": "4"}]' \
    3. http://localhost:8001/api/v1/nodes/<your-node-name>/status

    Note: In the preceding request, ~1 is the encoding for the character / in the patch path. The operation path value in JSON-Patch is interpreted as a JSON-Pointer. For more details, see IETF RFC 6901, section 3.

    The output shows that the Node has a capacity of 4 dongles:

    Describe your Node:

    1. kubectl describe node <your-node-name>

    Once again, the output shows the dongle resource:

    1. Capacity:
    2. cpu: 2
    3. memory: 2049008Ki
    4. example.com/dongle: 4

    Now, application developers can create Pods that request a certain number of dongles. See .

    Discussion

    Extended resources are similar to memory and CPU resources. For example, just as a Node has a certain amount of memory and CPU to be shared by all components running on the Node, it can have a certain number of dongles to be shared by all components running on the Node. And just as application developers can create Pods that request a certain amount of memory and CPU, they can create Pods that request a certain number of dongles.

    Suppose a Node has 800 GiB of a special kind of disk storage. You could create a name for the special storage, say example.com/special-storage. Then you could advertise it in chunks of a certain size, say 100 GiB. In that case, your Node would advertise that it has eight resources of type example.com/special-storage.

    1. Capacity:
    2. ...

    If you want to allow arbitrary requests for special storage, you could advertise special storage in chunks of size 1 byte. In that case, you would advertise 800Gi resources of type example.com/special-storage.

    Then a Container could request any number of bytes of special storage, up to 800Gi.

    Here is a PATCH request that removes the dongle advertisement from a Node.

    1. PATCH /api/v1/nodes/<your-node-name>/status HTTP/1.1
    2. Accept: application/json
    3. Host: k8s-master:8080
    4. [
    5. {
    6. "op": "remove",
    7. "path": "/status/capacity/example.com~1dongle",
    8. }
    9. ]

    Start a proxy, so that you can easily send requests to the Kubernetes API server:

    1. kubectl proxy

    In another command window, send the HTTP PATCH request. Replace <your-node-name> with the name of your Node:

    1. curl --header "Content-Type: application/json-patch+json" \
    2. --request PATCH \
    3. --data '[{"op": "remove", "path": "/status/capacity/example.com~1dongle"}]' \
    4. http://localhost:8001/api/v1/nodes/<your-node-name>/status

    (you should not see any output)

    What’s next