Re: [kubernetes/kubernetes] Specify multiple namespaces while querying the cluster (#52326)

2 views
Skip to first unread message

Jordan Liggitt

unread,
Sep 12, 2017, 11:49:58β€―AM9/12/17
to kubernetes/kubernetes, k8s-mirror-cli-feature-requests, Team mention

getting individual items across multiple namespaces is unusual, and the impact of making the namespace flag inconsistent across kubectl commands doesn't seem worth it to me

cc @kubernetes/sig-cli-feature-requests

β€”
You are receiving this because you are on a team that was mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.

Brendan

unread,
Nov 1, 2017, 4:02:04β€―AM11/1/17
to kubernetes/kubernetes, k8s-mirror-cli-feature-requests, Team mention

@liggitt: From a programmatic point of view, true. This is unusual. You can just make two (or more) separate queries. However, from an ops pov, it makes sense that this is something that should "just work".

I was disappointed to realise it wouldn't work as-is. :-/

fejta-bot

unread,
Apr 6, 2018, 6:23:54β€―PM4/6/18
to kubernetes/kubernetes, k8s-mirror-cli-feature-requests, Team mention

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

fejta-bot

unread,
May 6, 2018, 6:39:48β€―PM5/6/18
to kubernetes/kubernetes, k8s-mirror-cli-feature-requests, Team mention

Stale issues rot after 30d of inactivity.
Mark the issue as fresh with /remove-lifecycle rotten.
Rotten issues close after an additional 30d of inactivity.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.

/lifecycle rotten
/remove-lifecycle stale

Brendan

unread,
May 8, 2018, 9:28:05β€―AM5/8/18
to kubernetes/kubernetes, k8s-mirror-cli-feature-requests, Team mention

I wouldn't narrow the scope to say that the request is to change the addressability in only certain commands. I cannot imagine any commands where it should be treated differently.

Jordan Liggitt

unread,
May 8, 2018, 9:34:14β€―AM5/8/18
to kubernetes/kubernetes, k8s-mirror-cli-feature-requests, Team mention

allowing --namespace to arbitrarily contain multiple namespaces turns every command into needing to run in a loop, and handle partial success. rather than pushing that complexity into every command, I think it is better to invoke kubectl multiple times.

Ali Lahijani

unread,
May 10, 2018, 10:57:02β€―PM5/10/18
to kubernetes/kubernetes, k8s-mirror-cli-feature-requests, Team mention

Bash brace expansion can do it to some degree. Unfortunately you have to use quotes or escape special characters.

eval 'kubectl --context='{context1,context2}' --namespace='{ns1,ns2}' get pod;'
eval kubectl\ --context={context1,context2}\ --namespace={ns1,ns2}\ get\ pod\;

fejta-bot

unread,
Jun 9, 2018, 11:04:42β€―PM6/9/18
to kubernetes/kubernetes, k8s-mirror-cli-feature-requests, Team mention

Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.


Mark the issue as fresh with /remove-lifecycle rotten.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/close

k8s-ci-robot

unread,
Jun 9, 2018, 11:04:43β€―PM6/9/18
to kubernetes/kubernetes, k8s-mirror-cli-feature-requests, Team mention

Closed #52326.

Christian Hernandez

unread,
Dec 2, 2020, 5:57:32β€―PM12/2/20
to kubernetes/kubernetes, k8s-mirror-cli-feature-requests, Team mention

I'm wondering if we can provide --namespace multiple times. Wouldn't that get rid of the issue of turns every command into needing to run in a loop?

β€”
You are receiving this because you are on a team that was mentioned.

Reply to this email directly, view it on GitHub, or unsubscribe.

Stefan Lasiewski

unread,
Dec 3, 2020, 9:25:26β€―PM12/3/20
to kubernetes/kubernetes, k8s-mirror-cli-feature-requests, Team mention

@christianh814 No, this isn't possible for reasons stated in #71032. It's an oft-requested feature. I came here to see if it was supported yet, and just happened to see your comment.

If you use kubectl --namespace=ns1 --namespace=ns2 ... it will only show you the resources in ns2.

andrew-ryan-cr

unread,
May 6, 2021, 12:50:39β€―AM5/6/21
to kubernetes/kubernetes, k8s-mirror-cli-feature-requests, Team mention

Looks like this type of behavior is possible, depending on the use case, with field-selectors:
https://kubernetes.io/docs/concepts/overview/working-with-objects/field-selectors/

For example, the command below gets pods from all namespaces, but then excludes pods with the field 'metadata.namespace' equal to kube-system or longhorn-system:
watch kubectl get pods -A --field-selector metadata.namespace!=kube-system,metadata.namespace!=longhorn-system

It is also possible to use multiple includes rather than excludes. It works for my "ops" use-case. Figured I would post this here in case anyone saw this thread and thought it was a dead end.

Stefan Lasiewski

unread,
May 6, 2021, 12:44:26β€―PM5/6/21
to kubernetes/kubernetes, k8s-mirror-cli-feature-requests, Team mention

@andrew-ryan-cr That's an great solution, actually.

Would you know how to use multiple includes? This doesn't work for me, for example:

$ kubectl get pods -A --field-selector metadata.namespace==kube-system,metadata.namespace==cattle-system
No resources found

But selecting one does work:

$ kubectl get pods -A --field-selector metadata.namespace==kube-system
kube-system   coredns-1234-abcd                   1/1     Running     0          16h
kube-system   coredns-5678-efgh                   1/1     Running     0          16h
...

Brendan

unread,
May 6, 2021, 4:25:13β€―PM5/6/21
to kubernetes/kubernetes, k8s-mirror-cli-feature-requests, Team mention

@stefanlasiewski multiple includes don't work because it requires the result to match with both conditions instead of either condition. There have been other requests to allow selectors to specify a regular expression, which would resolve this problem, but that was also rejected.

Scorito-Dev

unread,
Oct 20, 2021, 7:53:50β€―AM10/20/21
to kubernetes/kubernetes, k8s-mirror-cli-feature-requests, Team mention

This would be a handy feature, please revisit for 1.23 :)

β€”
You are receiving this because you are on a team that was mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.

Triage notifications on the go with GitHub Mobile for iOS or Android.

mihica123

unread,
Jan 5, 2022, 8:47:45β€―AM1/5/22
to kubernetes/kubernetes, k8s-mirror-cli-feature-requests, Team mention

I support this request.

β€”


Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.

You are receiving this because you are on a team that was mentioned.Message ID: <kubernetes/kubernetes/issues/52326/1005699594@github.com>

mikedizzle

unread,
Jan 12, 2022, 12:12:25β€―PM1/12/22
to kubernetes/kubernetes, k8s-mirror-cli-feature-requests, Team mention

This would be a nice to have.

β€”
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.

You are receiving this because you are on a team that was mentioned.Message ID: <kubernetes/kubernetes/issues/52326/1011270266@github.com>

JakeReise

unread,
Jan 19, 2022, 1:14:36β€―PM1/19/22
to kubernetes/kubernetes, k8s-mirror-cli-feature-requests, Team mention

Would be helpful to have a call for essentially all-namespaces I have access to. That way I don't need cluster permissions to get resources across multiple namespaces. Can currently cycle through each namespace and gather resource information and store but that does not scale. A single API call to gather these resources would significantly reduce the time it takes to gather resource information. Example being: get routes --all-namespace-with-access would get all routes in namespaces I have access to instead of attempting to get them at the cluster level which is reserved.

β€”
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.

You are receiving this because you are on a team that was mentioned.Message ID: <kubernetes/kubernetes/issues/52326/1016736879@github.com>

Bibin Sebastian

unread,
Feb 3, 2022, 7:21:54β€―PM2/3/22
to kubernetes/kubernetes, k8s-mirror-cli-feature-requests, Team mention

Yeap . It would be great to apply commands across multiple namespaces without having to do one by one.

β€”
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.

You are receiving this because you are on a team that was mentioned.Message ID: <kubernetes/kubernetes/issues/52326/1029524382@github.com>

AdamMAtWork

unread,
Mar 31, 2022, 2:17:04β€―PM3/31/22
to kubernetes/kubernetes, k8s-mirror-cli-feature-requests, Team mention

@liggitt @zatricky The ability to operate on multiple namespaces doesn't need to work for all commands - it'd be sufficient for just "get", since "get" already supports either one namespace or all namespaces.

/reopen

β€”
Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are on a team that was mentioned.Message ID: <kubernetes/kubernetes/issues/52326/1084946759@github.com>

Kubernetes Prow Robot

unread,
Mar 31, 2022, 2:17:24β€―PM3/31/22
to kubernetes/kubernetes, k8s-mirror-cli-feature-requests, Team mention

@AdamMAtWork: You can't reopen an issue/PR unless you authored it or you are a collaborator.

In response to this:

@liggitt @zatricky The ability to operate on multiple namespaces doesn't need to work for all commands - it'd be sufficient for just "get", since "get" already supports either one namespace or all namespaces.

/reopen

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

β€”
Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are on a team that was mentioned.Message ID: <kubernetes/kubernetes/issues/52326/1084947033@github.com>

Tomas Sandven

unread,
Jun 13, 2022, 1:30:17β€―PM6/13/22
to kubernetes/kubernetes, k8s-mirror-cli-feature-requests, Team mention

My use case for this is that I have deployments across 3 namespaces, and I want to show all deployments, services or pods across these 3 namespaces. If I specify --all-namespaces then I also get a ton of noise from cert-manager, ingress-nginx and kube-system, which I don't want.

A nice workaround would be if I could specify --all-namespaces, then filter by namespace afterwards with a regular expression or pattern, something like:

kubectl get pods --all-namespaces --field-selector "metadata.namespace~*my-project*"

But sadly that's not possible either πŸ˜•

β€”
Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are on a team that was mentioned.Message ID: <kubernetes/kubernetes/issues/52326/1154191753@github.com>

Karthik Ananth

unread,
Jun 15, 2022, 11:36:00β€―AM6/15/22
to kubernetes/kubernetes, k8s-mirror-cli-feature-requests, Team mention

I was also looking for commands to do this, but since I found none, I resorted to this (windows terminal) -

kubectl get po -n namepsace1; echo ""; kubectl get po -n namespace2

β€”
Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are on a team that was mentioned.Message ID: <kubernetes/kubernetes/issues/52326/1156626750@github.com>

Christian Hernandez

unread,
Jun 15, 2022, 6:46:11β€―PM6/15/22
to kubernetes/kubernetes, k8s-mirror-cli-feature-requests, Team mention

FWIW, I did this with a plugin (so all client side)

#!/bin/bash
#
if [[ ${#*} -eq 0 ]] || [[ ${#3} -eq 0 ]]; then
	echo "Usage: kubectl space -n foo,bar,bazz pods"
	exit 2
fi

#
## toptions
while getopts "n:(namespace)" opts
do
	case "${opts}" in
		n)
			ns="${OPTARG}"
		;;
	esac
done

namespaces=(${ns//,/ })

for namespace in ${namespaces[*]}
do
	echo "------------"
	echo "${namespace}"
	echo "------------"
	kubectl get $3 -n ${namespace}
done
##
##

Saved it as kubectl-space and now I run kubectl space -n foo,bar pods

It's crude (probably will write a better one in go) but it works for what I need now.

β€”
Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are on a team that was mentioned.Message ID: <kubernetes/kubernetes/issues/52326/1157022134@github.com>

Kyle Sanderson

unread,
Sep 23, 2022, 9:00:47β€―PM9/23/22
to kubernetes/kubernetes, k8s-mirror-cli-feature-requests, Team mention

This is incredibly silly to not have in the core product. I constantly try to reference multiple namespaces when scaling a deployment and it doesn't work.

β€”
Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are on a team that was mentioned.Message ID: <kubernetes/kubernetes/issues/52326/1256822093@github.com>

Emilano Vazquez

unread,
Sep 29, 2022, 5:08:20β€―PM9/29/22
to kubernetes/kubernetes, k8s-mirror-cli-feature-requests, Team mention

This is incredibly silly to not have in the core product. I constantly try to reference multiple namespaces when scaling a deployment and it doesn't work.

It's opensource, you can share your knowledge and make a PR ?

β€”
Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are on a team that was mentioned.Message ID: <kubernetes/kubernetes/issues/52326/1262817037@github.com>

Jeansen

unread,
May 14, 2023, 6:06:11β€―AM5/14/23
to kubernetes/kubernetes, k8s-mirror-cli-feature-requests, Team mention

In principle, I have the same wish. But with respect to a uniform CLI and keeping it rock solid, simple and manageable, I agree with #71032 (comment). Only being able to select multiple namespaces in 'get' would make the CLI "unstable". Yes, it is a nice feature. On the other hand, writing a little shell function, creating an alias for it and calling that one instead of kubectl get, isn't really that hard. And with some help of shell scripting one can create all sorts of little helper commands.

β€”
Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are on a team that was mentioned.Message ID: <kubernetes/kubernetes/issues/52326/1546861506@github.com>

Paolo

unread,
Oct 17, 2023, 6:38:00β€―AM10/17/23
to kubernetes/kubernetes, k8s-mirror-cli-feature-requests, Team mention

getting individual items across multiple namespaces is unusual

I don't see why this means a user shouldn't be able to do it

β€”
Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are on a team that was mentioned.Message ID: <kubernetes/kubernetes/issues/52326/1766144720@github.com>

heover1cks

unread,
Apr 30, 2024, 10:35:53β€―PM4/30/24
to kubernetes/kubernetes, k8s-mirror-cli-feature-requests, Team mention

As --all-namespaces is supported, I think allowing multiple namespaces for a query also makes sense.

β€”
Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are on a team that was mentioned.Message ID: <kubernetes/kubernetes/issues/52326/2087889676@github.com>

Gerrard Geldenhuis

unread,
Jul 27, 2024, 5:21:27β€―AM7/27/24
to kubernetes/kubernetes, k8s-mirror-cli-feature-requests, Team mention

A shame this request is closed it would have been handy.

β€”
Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are on a team that was mentioned.Message ID: <kubernetes/kubernetes/issues/52326/2254090135@github.com>

AndrΓ© Mitrica

unread,
Aug 16, 2024, 6:38:22β€―AM8/16/24
to kubernetes/kubernetes, k8s-mirror-cli-feature-requests, Team mention

Absolutely a useful feature that I've been missing for a few years now.

β€”
Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are on a team that was mentioned.Message ID: <kubernetes/kubernetes/issues/52326/2293267835@github.com>

mimparat132

unread,
Oct 3, 2024, 2:48:59β€―PM10/3/24
to kubernetes/kubernetes, k8s-mirror-cli-feature-requests, Team mention

I don't think this is an unusual request. I manage many multi-tenant kubernetes clusters. Teams would like to list pods across the namespaces they own. Without the ability to get resources against a slice of namespaces, teams would have to be given the ability to list pods across all namespaces. One team shouldn't be able to list the pods of another team.
If kubectl get pods -A functioned in a way that it would only list pods in the namespaces a config had access to, that would be great.

β€”
Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are on a team that was mentioned.Message ID: <kubernetes/kubernetes/issues/52326/2392096874@github.com>

anandhukrishnan.v

unread,
Mar 18, 2025, 7:12:45β€―AMMar 18
to kubernetes/kubernetes, k8s-mirror-cli-feature-requests, Team mention

+1

β€”
Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are on a team that was mentioned.Message ID: <kubernetes/kubernetes/issues/52326/2732781116@github.com>

anandhu-co-inanandhu-co-in left a comment (kubernetes/kubernetes#52326)

+1

β€”
Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are on a team that was mentioned.Message ID: <kubernetes/kubernetes/issues/52326/2732781116@github.com>

CodeBirb

unread,
May 9, 2025, 8:43:00β€―AMMay 9
to kubernetes/kubernetes, k8s-mirror-cli-feature-requests, Team mention
Mungari left a comment (kubernetes/kubernetes#52326)

+1

β€”
Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are on a team that was mentioned.Message ID: <kubernetes/kubernetes/issues/52326/2866401756@github.com>

Jean Morais

unread,
May 27, 2025, 5:18:33β€―PMMay 27
to kubernetes/kubernetes, k8s-mirror-cli-feature-requests, Team mention
jeanmorais left a comment (kubernetes/kubernetes#52326)

Very useful feature when using multi-tenant clusters.

β€”
Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are on a team that was mentioned.Message ID: <kubernetes/kubernetes/issues/52326/2914078534@github.com>

udayraj-rzp

unread,
Jun 20, 2025, 6:37:39β€―AMJun 20
to kubernetes/kubernetes, k8s-mirror-cli-feature-requests, Team mention
udayraj-rzp left a comment (kubernetes/kubernetes#52326)

+1

β€”


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are on a team that was mentioned.Message ID: <kubernetes/kubernetes/issues/52326/2990883689@github.com>

Reply all
Reply to author
Forward
0 new messages