<p>Is it possible to get K8s resource limits in <em>absolute units</em>? By default we get a human-readable units (like Mi, Gi, for memory) and m for CPU:</p>
<pre><code>$ kubectl get pod ndbmysqld-1 -o yaml | grep -A 6 &quot; resources:&quot; | grep &quot;limits:&quot; -A 2
      limits:
        cpu: 500m
        memory: 512Mi
--
      limits:
        cpu: 100m
        memory: 256Mi
</code></pre>
<p>But my Pods have all different units, see this one:</p>
<pre><code>      limits:
        cpu: &quot;1&quot;
        memory: 214748364800m
</code></pre>
<p>NB: 214748364800m is apparently 200Mi...</p>
<p>Any way to get all units aligned?</p>
<p>Thanks!</p>

Jarek
<p>2 ways to do this: use numfmt. You can use this to reformat numeric columns which is really convenient if you pull out tsv data from kubectl. This is what I'd recommend.</p>
<pre><code>kubectl get pods -o json |jq -r '.items[]|.metadata as $m|.spec.containers[].resources[]|[$m.name, .memory]|@tsv' \
|numfmt --field=2 --from=auto
</code></pre>
<p>alternatively you can approximate it in plain jq (if you don't have numfmt or you need it in jq for differently-formatted output):</p>
<pre><code>kubectl get pods -o json \
|jq -r 'def units: .|capture(&quot;(?&lt;n&gt;[0-9]+)(?&lt;u&gt;[A-Za-z]?)&quot;)|. as $v|($v.n|tonumber)*(if $v.u==&quot;&quot; then 1 else pow(10;3*(&quot;m_KMGTPE&quot;|index($v.u)-1)) end); 
.items[].spec.containers[].resources[].memory|units'
</code></pre>
<p>Highlighting just the function I defined in there:</p>
<pre><code>def units: 
 .|capture(&quot;(?&lt;n&gt;[0-9]+)(?&lt;u&gt;[A-Za-z]?)&quot;)
  |. as $v
  |($v.n|tonumber)*(
    if $v.u==&quot;&quot; then 1 
    else pow(10;3*(&quot;m_KMGTPE&quot;|index($v.u)-1)) 
    end)
</code></pre>
<p>what this does is capture the number part and the first character of the suffix as 'n' and 'u', then returns 'n' times 10^3*(index of the suffix in &quot;m_KMGTPE&quot; minus one). eg for 'm' the index is 0 so it multiplies by 10^-3, for 1 the index is 2 so it multiplies by 10^3, and so on.</p>
