Kubectl get info about resource with templates and yaml
I wanted the metadata.annotation pod-requests, viewable in node config -> YAML on the Rancher webgui.
Came up w/ this:
kubectl get node node-name -o template --template='{{ index .metadata.annotations "management.cattle.io/pod-requests" }}'
# | jq '.["nvidia.com/gpu"]'
It refused to allow me to use - and / inside the name (k get node nodename -o template --template={{.metadata.annotations.management.cattle.io/pod-requests}} didn’t work), solution from Helm templating doesn’t let me use dash in names - Stack Overflow.
Fun version w/ templates and json (there has to be a better way):
k get node nodename -o template --template='{"requests": {{ index .metadata.annotations "management.cattle.io/pod-requests" }}, "limits": {{ index .metadata.annotations "management.cattle.io/pod-requests" }}, "total": {"nvidia.com/gpu": {{ index .metadata.labels "nvidia.com/gpu.count" }} } }' | jq .
Returns:
{
"requests": {
"cpu": "19795m",
"memory": "7450Mi",
"nvidia.com/gpu": "1",
"pods": "37"
},
"limits": {
"cpu": "19795m",
"memory": "7450Mi",
"nvidia.com/gpu": "1",
"pods": "37"
},
"total": {
"nvidia.com/gpu": 1
}
}
Or even
k get node ki-srv03 -o template --template='{"requests": {{ index .metadata.annotations "management.cattle.io/pod-requests" }}, "limits": {{ index .metadata.annotations "management.cattle.io/pod-requests" }}, "total": {"nvidia.com/gpu": {{ index .metadata.labels "nvidia.com/gpu.count" }} } }' | jq '. | [.requests["nvidia.com/gpu"], .limits["nvidia.com/gpu"], .total["nvidia.com/gpu"] | tonumber]' -c
# -> [2,1,4]
Nel mezzo del deserto posso dire tutto quello che voglio.
comments powered by Disqus