Skip to content

Instantly share code, notes, and snippets.

@mjhuber
Created May 7, 2019 20:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mjhuber/beebbb42194f316d4a2a038e275aeefd to your computer and use it in GitHub Desktop.
Save mjhuber/beebbb42194f316d4a2a038e275aeefd to your computer and use it in GitHub Desktop.
Get k8s resources
#!/usr/bin/env bash
NAMESPACE="default"
DEPLOYMENTS=$(kubectl get deploy -n $NAMESPACE --no-headers | awk '{print $1}')
for deploy in $DEPLOYMENTS; do
echo "$deploy"
resources=$(kubectl get deploy/$deploy -n $NAMESPACE -o json | jq '.spec.template.spec.containers[0].resources')
mem_limit=$(echo $resources | jq '.limits.memory')
mem_req=$(echo $resources | jq '.requests.memory')
cpu_limit=$(echo $resources | jq '.limits.cpu')
cpu_req=$(echo $resources | jq '.requests.cpu')
printf "\tMemory:\n\t Requests: %s\n\t Limits: %s\n\n" $mem_req $mem_limit
printf "\tCPU:\n\t Requests: %s\n\t Limits: %s\n\n\n" $cpu_req $cpu_limit
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment