Last active
September 12, 2018 08:50
-
-
Save ejber-ozkan/26fa1ff4f5aaf20ac5ec7792ed77a07e to your computer and use it in GitHub Desktop.
Kubernetes get current quotas in namespaces to CSV
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
jq into jq eeek!