wtorek, 18 października 2022

k8grep: Yet Another Ultimate Kubernetes Tool

Hello!

Maybe you're struggling how to find any IP in your Kubernetes cluster? [*]

Or you want to find out what images your deployments use? [**]

Or you need to know which configmaps or secrets have to anything with Redis? [***]

Here's a powerful func in bash to find almost ANY information about my current kubernetes cluster:

k8grep () {
	local objtype=$1
	shift 1
	local grep_args="$@"
	[ "$objtype" -a "$grep_args" ] || {
		echo "# usage: k8grep OBJTYPE GREP_ARGS"
		echo "# example: k8grep pod -n -m 5 postgres"
		return
	}
	kubectl get --no-headers "$objtype" --all-namespaces |
		while read namespace object junk; do
			echo "# kubectl get -n $namespace $objtype $object"
			kubectl get $objtype -n $namespace $object -oyaml | grep $grep_args
		done
}

See it in action. This is what I am getting after running k8grep configmap 'REDIS_\w\+' -n -1

k8grep in action

By the way, answers to questions (LOL, dare I compete with StackOverflow?) are:

How to find any IP in your Kubernetes cluster?

k8grep endpoints 10.11.12.134

How do I find out what images my k8s deployments use?

k8grep deployment -n "image: "

How do I find which config maps and secrets contain anything about Redis?

for t in configmap secret; do k8grep $t -m1 -n -i redis; done