Skip to content

Instantly share code, notes, and snippets.

@ejber-ozkan
Last active September 12, 2018 08:50
Show Gist options
  • Save ejber-ozkan/26fa1ff4f5aaf20ac5ec7792ed77a07e to your computer and use it in GitHub Desktop.
Save ejber-ozkan/26fa1ff4f5aaf20ac5ec7792ed77a07e to your computer and use it in GitHub Desktop.
Kubernetes get current quotas in namespaces to CSV
#!/bin/bash
echo "get-current-k8s-quotas.bash "
echo "... Outputs daily quotas hard limits and actual usage"
echo "... Requires kubectl, jq and access to k8s clusters and kubectl already"
echo "..."
export DATE=`date '+%Y-%m-%d-%H'`
for i in namespace1 namespace2 namespace3 namespace4
do
if [ ${i} != 'namespaceprod' ]
then
kubectx ${i}
echo "quota_name,namespace,hard_limit_cpu,hard_limit_mem,used_cpu,used_mem " > daily-quotas-${i}-${DATE}.csv
kubectl get quota -o json --all-namespaces | jq -r '[.items[] | {quotaname:.metadata.name,namespace:.metadata.namespace, speccpu:.status.hard."limits.cpu",specmem:.status.hard."limits.memory", usedcpu:.status.used."limits.cpu",usedmem:.status.used."limits.memory" }]' | jq -r 'map([.quotaname, .namespace, .speccpu, .specmem, .usedcpu, .usedmem] | join(",")) | join("\n")' >> daily-quotas-${i}-${DATE}.csv
fi
done
@ejber-ozkan
Copy link
Author

jq into jq eeek!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment