Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add -N,--names-only flag to kubectl get #16700

Closed
mml opened this issue Nov 3, 2015 · 3 comments
Closed

Add -N,--names-only flag to kubectl get #16700

mml opened this issue Nov 3, 2015 · 3 comments

Comments

@mml
Copy link
Contributor

mml commented Nov 3, 2015

Many admin operations are made easier by fetching a list of the names of things, e.g. into a shell variable. See below for an example. Rather than hacking up a template, asking for just the names should be a normal flag.

% nodes=$(kubectl get nodes -lfoo=bar -otemplate --template='{{range .items}}{{.metadata.name}} {{end}}')
% for node in $nodes; do
for> echo $node
for> done

# Sanity check before beginning work.
% echo $nodes | wc -w
4

% for node in $nodes; do 
for> kubectl drain --force $node
for> maintenance_script $node
for> kubectl undrain $node
for> sleep 900
for> done
@mikedanese
Copy link
Member

You could use jsonpath to make it a little shorter but still not great

k get no -o jsonpath="{.items[*].metadata.name}" | xargs -d ' ' -I {} kubectl drain {}

@hurf
Copy link
Contributor

hurf commented Nov 3, 2015

Try kubectl get no -o name

@thockin
Copy link
Member

thockin commented Nov 3, 2015

you want -o name

On Mon, Nov 2, 2015 at 4:37 PM, Matt Liggett notifications@github.com
wrote:

Many admin operations are made easier by fetching a list of the names of
things, e.g. into a shell variable. See below for an example. Rather than
hacking up a template, asking for just the names should be a normal flag.

% nodes=$(kubectl get nodes -lfoo=bar -otemplate --template='{{range .items}}{{.metadata.name}} {{end}}')
% for node in $nodes; do
for> echo $node
for> done

Sanity check before beginning work.

% echo $nodes | wc -w
4

% for node in $nodes; do
for> kubectl drain --force $node
for> maintenance_script $node
for> kubectl undrain $node
for> sleep 900
for> done


Reply to this email directly or view it on GitHub
#16700.

@thockin thockin closed this as completed Nov 3, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants