#kube #kubernetes #namespaces

bin+lib kube-anypod

Command line utility to quickly get the name of a random pod from a Deployment, StatefulSet or DaemonSet

1 unstable release

new 0.2.0 Feb 23, 2025

#1165 in Command line utilities

BSD-3-Clause

18KB
339 lines

anypod

A quick way to get a random pod's name for a given Deployment, StatefulSet, or DaemoneSet

Motivation

I often find myself needing to exec into a running pod to check out something in situ or to run a command in one of the pods of some Deployment. It does not matter at all WHICH pod I choose, I just need one of the current pods.

I got tired of having to run kubectl -n whatever get pods | grep my-deployment-prefix and then cut-n-paste that into what I'm trying to do.

Example

If we have Deployment named ingress-nginx-controller in the nginx-ingress namespace and we run:

$ anypod -n nginx-ingress ingress 

It will output the name of a single pod running from that Deployment like so:

$ anypod -n nginx-ingress ingress 
ingress-nginx-controller-69fbfb4bfd-dvn8d

Usage

NOTE: All queries are prefix queries. So if you run anypod f it will use the first workload it finds that starts with the letter 'f'

# Return the name of the nginx Deployment in the current namespace 
$ anypod ingress
ingress-nginx-controller-69fbfb4bfd-dvn8d

# Return the name of the nginx Deployment in the `other` namespace
$ anypod --namespace other nginx
nginx-79f798ccd6-j7d6s

# or 

$ anypod -n other nginx
nginx-79f798ccd6-j7d6s

# Specifically look for statefulset name
$ anypod statefulset/postgresql

# Specifically look for daemonset name
$ anypod daemonset/dd-agent

In the event anypod does not find any matching workloads it will tell you the namespace it is currently searching in and will list all of the various workloads it DID find so you can re-run your query.

Install

Pre-built binaries

You can find pre-built binaries that you can download and drop into your $PATH here with the releases.

Build via Cargo

If you have a local rust toolchain set up you can build and install this manually with:

$ git clone ... ~/src/kube-anypod/
$ cargo install --path ~/src/kubeanypod/

Dependencies

~50–80MB
~1M SLoC