0

I tried this script to see kubernetes volumes usage

k get pods -n elk | jq -s '[flatten | .[].pods[].volume[]? | select(has("pvcRef")) ''{name: .pvcRef.name, capacityBytes, usedBytes, availableBytes, ''percentageUsed: (.usedBytes / .capacityBytes * 100)}]' 

got this

{name: .pvcRef.name, capacityBytes, usedBytes, availableBytes, percentageUsed: (.usedBytes / .capacityBytes * 100)}] jq: 1 compile error 

My pods

 k get pods -n elk 

k get pods -n elk

NAME READY STATUS RESTARTS AGE elasticsearch-master-0 1/1 Running 0 24d elasticsearch-master-1 1/1 Running 0 24d filebeat-filebeat-8jdqn 1/1 Running 0 24d filebeat-filebeat-vl9js 1/1 Running 0 24d filebeat-filebeat-xx2fm 1/1 Running 0 24d filebeat-filebeat-zdj5k 1/1 Running 0 22d kibana-kibana-9f5c6f974-kzzpr 0/1 Running 0 24d logstash-logstash-0 1/1 Running 26 (19h ago) 24d then k describe kibana 

gives

Volumes: kube-api-access-2pizdku: Type: Projected (a volume that contains injected data from multiple sources) TokenExpirationSeconds: 3607 ConfigMapName: kube-root-ca.crt ConfigMapOptional: <nil> 

And volume

 k get pv -n elk NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE pvc-0462020 30Gi RWO Delete Bound elk/elasticsearch-master-elasticsearch-master-1 default 

Why?

6
  • I recommend adding details, much more details... Commented Jan 20 at 16:45
  • Post the output of k get pods -n elk at least. Commented Jan 20 at 16:56
  • @choroba Added,pls take a look. Commented Jan 20 at 16:59
  • 1
    You get a syntax error because it's obviously not valid jq syntax. Those '' also suggest you may have messed up some copy-pasting. Commented Jan 20 at 17:07
  • 2
    Also, the output to jq should be a JSON. The output of k get pods -n elk doesn't look like JSON to me (unrelated to the error, though). Commented Jan 20 at 17:22

1 Answer 1

2

Your jq expression, with extra whitespace inserted for readability:

[ flatten | .[].pods[].volume[]? | select(has("pvcRef")) { name: .pvcRef.name, capacityBytes, usedBytes, availableBytes, percentageUsed: (.usedBytes / .capacityBytes * 100) } ] 

What's missing is a pipe symbol after the select() stage of the filter. Inserting it makes it syntactically correct:

[ flatten | .[].pods[].volume[]? | select(has("pvcRef")) | { name: .pvcRef.name, capacityBytes, usedBytes, availableBytes, percentageUsed: (.usedBytes / .capacityBytes * 100) } ] 

Whether the expression is correct in all other senses is unknown, as I don't know what the input is expected to look like. The text quoted in the question isn't JSON, so jq wouldn't be able to apply the expression to it directly.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.