How to understand the "Opaque Integer Resources" in Kubernetes resource model?

2/19/2017

I'm reading some document about k8s resource model, but I'm puzzled with "Opaque Integer Resources" in here, what's the exactly "opaque" mean?

thanks for your help~

-- litanhua
kubernetes

2 Answers

2/19/2017

Kubernetes understands what CPU and memory are and can discover these resources by various means. So a node might have 4 CPUs and 32GB memory. Pods can request these resources and the scheduler will make sure that a Pod is scheduled on a node that have enough of these resources still available.

But there can be other types of resources. Say some of your nodes have special USB dongles attached for BitCoin mining, 8 plugged into each of those nodes. This resource is called an opaque resource as Kubernetes doesn't understand what a BitCoin mining dongle is (that is, a waste of money).

With the Opaque Integer Resources feature you can declare that there is such a thing as a BitCoin mining dongle and that a specific node has 8 of them. It's called an integer resource as it's not possible to have 3.5 dongles attached to a node and also a Pod may not request 1.5 dongles to do it's job.

Another example could be that some of your nodes are equipped with a 1TB SSD. You could specify their sizes in MBs and attach this information to the node. Let's call the resource ssdmb. Now your database application could requrest 400 of the ssdmb resource. Altough Kubernetes has no clue what an ssdmb is now it understands that your Pod needs to be scheduled on a node that has ssdmb resource available and at least 400 of it is still available.

To mark the node named node-2 as having 1000 of the ssdmb (the URL assumes you are running kubectl proxy on your machine):

curl -X PATCH \
  --header "Accept: application/json" \
  --header "Content-Type: application/json-patch+json" \
  --data-raw '[{"op":"add", "path":"/status/capacity/pod.alpha.kubernetes.io~1opaque-int
-resource-ssdmb", "value":"1000"}]' \
  http://127.0.0.1:8001/api/v1/nodes/node-2/status

The same can be achieved with

kubectl patch node node-2 \
  --patch='[{"op":"add", "path":"/status/capacity/pod.alpha.kubernetes.io~1opaque-int
-resource-ssdmb", "value":"1000"}]'

Then, to make your Pod request this resource you could:

apiVersion: v1
kind: Pod
metadata:
  name: my-pod
spec:
  containers:
  - name: my-container
    image: myimage
    resources:
      requests:
        cpu: 1
        pod.alpha.kubernetes.io/opaque-int-resource-ssdmb: 400

After you create this Pod and do kubectl describe node node-2 you will see something like this:

Capacity:                                                                                                             
 cpu:                                                   2    
 pod.alpha.kubernetes.io/opaque-int-resource-ssdmb:     1k   
 pods:                                                  110
Allocatable:
 cpu:                                                   1
 pod.alpha.kubernetes.io/opaque-int-resource-ssdmb:     600
 pods:                                                  109
-- Janos Lenart
Source: StackOverflow

2/19/2017

In this case opaque just means, that Kubernetes doesn't know and doesn't need to know what kind of resource you are defining. It doesn't matter if this is network bandwidth, disk space or moos. The cluster administrators are responsible for defining and managing these values.

-- svenwltr
Source: StackOverflow