<p>I'm reading some document about k8s resource model, but I'm puzzled with "Opaque Integer Resources" in <a href="https://kubernetes.io/docs/user-guide/compute-resources/" rel="nofollow noreferrer">here</a>, what's the exactly "opaque" mean?</p>

<p>thanks for your help~</p>

<p>Kubernetes <em>understands</em> 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.</p>

<p>But there can be other types of resources. Say some of your nodes have special <a href="https://www.hobbymining.com/usb-bitcoin-miners/" rel="noreferrer">USB dongles attached for BitCoin mining</a>, 8 plugged into each of those nodes. This resource is called an <em>opaque</em> resource as Kubernetes doesn't <em>understand</em> what a BitCoin mining dongle is (that is, a waste of money).</p>

<p>With the <a href="https://kubernetes.io/docs/user-guide/compute-resources/#opaque-integer-resources-alpha-feature" rel="noreferrer">Opaque Integer Resources</a> 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 <em>integer</em> 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.</p>

<p>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 <code>ssdmb</code>. Now your database application could requrest 400 of the <code>ssdmb</code> resource. Altough Kubernetes has no clue what an <code>ssdmb</code> is now it understands that your Pod needs to be scheduled on a node that has <code>ssdmb</code> resource available and at least 400 of it is still available.</p>

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

<pre><code>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
</code></pre>

<p>The same can be achieved with</p>

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

<p>Then, to make your Pod request this resource you could:</p>

<pre><code>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
</code></pre>

<p>After you create this Pod and do <code>kubectl describe node node-2</code> you will see something like this:</p>

<pre><code>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
</code></pre>
