Skip to content

Instantly share code, notes, and snippets.

@redsfyre
Last active December 24, 2021 13:10
Show Gist options
  • Save redsfyre/f3fd4ec9fc76d49d2daed0c965805e0f to your computer and use it in GitHub Desktop.
Save redsfyre/f3fd4ec9fc76d49d2daed0c965805e0f to your computer and use it in GitHub Desktop.
Kubernetes & Openshift CLI Tricks -- WIP

Kubernetes list all deployments and their specs (requests/limits)

kubectl get deployments -o jsonpath='{range .items[*]}{"NAME:  "}{.metadata.name}{"\nSPEC:  \n  LIMITS  : "}{.spec.template.spec.containers[*].resources.limits}{"\n  REQUESTS: "}{.spec.template.spec.containers[*].resources.requests}{"\n\n"}{end}'

Kubernetes list all cronjobs and their specs (requests/limits)

kubectl get cronjobs -o jsonpath='{range .items[*]}{"NAME:  "}{.metadata.name}{"\nSPEC:  \n  LIMITS  : "}{.spec.jobTemplate.spec.template.spec.containers[*].resources.limits}{"\n  REQUESTS: "}{.spec.jobTemplate.spec.template.spec.containers[*].resources.requests}{"\n\n"}{end}'

Kubernetes list all pods and their specs - experimental, really WIP and requires jq

kubectl  get pods -ojson | jq '.items[] | .metadata.name + " " + .spec.containers[0].resources.requests.cpu + " " + .spec.containers[0].resources.limits.cpu + " " + .spec.containers[0].resources.requests.memory+ " " + .spec.containers[0].resources.limits.memory' | sed 's/"//g    ' | awk 'BEGIN { print "<table>" } { print "<tr><td>" $1 "</td><td>" $2 "</td><td> -- </td><td>" $3 "</td><td> -- </td><td>" $4 "</td><td> -- </td><td>" $5 "</td></tr>" } END { print "</table>" }' > /tmp/reqlim.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment