Kubernetes and Helm.
| Name | Runs | What it does | |
kbad | kubectl get pods -A --field-selector=status.phase!=Running,status.phase!=Succeeded | pods not running | needs kubectl |
kimages | kubectl get pods -A -o jsonpath="{..image}" | tr " " "\n" | sort | uniq -c | images in use | needs kubectl |
kgall | kubectl get all | everything in namespace | needs kubectl |
function ksecret {
[ "$#" -eq 2 ] || { echo "Usage: ksecret <secret> <key>" >&2; return 2; }
kubectl get secret "$1" -o jsonpath="{.data.$2}" | base64 -d; echo
}
ksecret NAME KEY | | print decoded value of one secret keyexample$ ksecret db-creds password
s3cret | needs kubectl |
function kshell {
[ "$#" -ge 1 ] || { echo "Usage: kshell <pod> [container]" >&2; return 2; }
kubectl exec -it "$1" ${2:+-c "$2"} -- sh
}
kshell POD | | shell into pod (sh)example$ kshell api-7d9f8b-x2k4
/app $ | needs kubectl |
function krun { kubectl run "tmp-$$" --rm -it --restart=Never --image="${1:-busybox:1.36}" -- sh; }
krun [IMAGE] | | throwaway debug pod, removed on exit (default busybox)example$ krun
If you don't see a command prompt, try pressing enter.
/ # | needs kubectl |
function kuse {
[ "$#" -eq 1 ] || { echo "Usage: kuse <context>" >&2; return 2; }
kubectl config use-context "$1"
}
kuse CONTEXT | | switch kubectl contextexample$ kuse prod
Switched to context "prod". | needs kubectl |
function knamespace {
[ "$#" -eq 1 ] || { echo "Usage: knamespace <namespace>" >&2; return 2; }
kubectl config set-context --current --namespace="$1"
}
knamespace NS | | set namespace for current contextexample$ knamespace payments
Context "prod" modified. | needs kubectl |
function kpf {
[ "$#" -ge 2 ] || { echo "Usage: kpf <resource> <local:remote>" >&2; return 2; }
kubectl port-forward "$@"
}
kpf RESOURCE LOCAL:REMOTE | | port-forwardexample$ kpf svc/api 8080:80
Forwarding from 127.0.0.1:8080 -> 80 | needs kubectl |
function kdebug {
[ "$#" -ge 1 ] || { echo "Usage: kdebug <pod> [image]" >&2; return 2; }
kubectl debug -it "$1" --image="${2:-busybox:1.36}"
}
kdebug POD [IMAGE] | | attach debug container (default busybox)example$ kdebug api-7d9f8b-x2k4
Defaulting debug container name to debugger-x7k2.
/ # | needs kubectl |