-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkubectl-nodetypes
executable file
·46 lines (38 loc) · 1.31 KB
/
kubectl-nodetypes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env bash
##
## This script can be used as a kubectl plugin. After saving this script somewhere in your PATH environment variable
## and ensuring that it is executable you can use it as a kubectl plugin.
##
## bash $ kubectl nodetypes
## bash $ kubectl nodetypes 2>/dev/null
##
## 2022.08.12
##
## Check out:
## https://kubernetes.io/docs/tasks/extend-kubectl/kubectl-plugins/
## https://kubernetes.io/docs/reference/kubectl/jsonpath/ (examples at the bottom of the page!)
##
set -euo pipefail
IFS=$'\n\t'
## http://redsymbol.net/articles/unofficial-bash-strict-mode/
## explains why we need above lines
tmpdir=$(mktemp -d /tmp/tmp.VL."$(basename "$0")".XXXXXXXXXX)
cleanup() {
rm -rf "${tmpdir}"
}
trap cleanup EXIT QUIT INT
podnodes() {
local NS
NS="${1:-default}"
>&2 printf "%s | %s\n" "Node" "Pod"
kubectl --namespace "${NS}" get -o=jsonpath='{range .items[*]}{.spec.nodeName}{" | "}{.metadata.name}{"\n"}{end}' pods
}
nodetypes() {
local NS
NS="${1:-default}"
>&2 printf "%s | %s\n" "Node" "InstanceType"
kubectl --namespace "${NS}" get -o=jsonpath='{range .items[*]}{.metadata.name}{" | "}{.metadata.labels.beta\.kubernetes\.io\/instance-type}{"\n"}{end}' nodes
}
podnodes "${1:-default}"
printf "%s\n" "----------------------------------------------------------" >&2
nodetypes "${1:-default}"