Skip to content

Instantly share code, notes, and snippets.

@dejanu
Created December 8, 2022 16:02
Show Gist options
  • Save dejanu/496c5b344de20009aa6c14ed1517d660 to your computer and use it in GitHub Desktop.
Save dejanu/496c5b344de20009aa6c14ed1517d660 to your computer and use it in GitHub Desktop.
wrapper for inspecting Requests/Limits for Pods
#!/usr/bin/env bash
#############################################################
# Purpose: wrapper for inspecting Requests/Limits for Pods ##
# @dejanualex ##
#############################################################
# read namespace and po
echo -e "Available namespaces are:\n $(kubectl get ns -o=custom-columns=NAMESPACES:.metadata.name) \n"
echo -e "\n Please write the name of the namespace for which you want to know the resource status:\n"
read -r nspace
echo -e "\n Please select a POD from namespace:\n $(kubectl -n "${nspace}" get po -o=custom-columns=POD:.metadata.name) \n"
read -r ppod
# check Limits and Requests for Containers in Pod
echo -e "........."
echo -e "\e[4mContainers in POD:\e[24m $(kubectl -n "${nspace}" get po "${ppod}" -o jsonpath='{.spec.containers[*].name}') \n"
echo -e "\e[4mLimits and Request per CONTAINER:\e[24m $(kubectl -n "${nspace}" get po "${ppod}" -o jsonpath='{.spec.containers[*].resources}'|jq .) \n"
echo -e "\e[4mCurrent resource usage:\e[24m\n"
kubectl -n "${nspace}" top po "${ppod}" --containers
# get the most expensive pods
echo -e "\e[4mMost CPU expensive pods in ${nspace} namespace:\e[24m\n $(kubectl top po -n "${nspace}" --sort-by=cpu)"
echo -e "\e[4mMost Memory expensive pods in ${nspace} namespace:\e[24m\n $(kubectl top po -n "${nspace}")"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment