kubectl: kubectl get all does not list all resources in a namespace
Is this a request for help? (If yes, you should use our troubleshooting guide and community support channels, see http://kubernetes.io/docs/troubleshooting/.):
What keywords did you search in Kubernetes issues before filing this one? (If you have found any duplicates, you should instead reply there.): get all, get all resources
Is this a BUG REPORT or FEATURE REQUEST? (choose one): BUG REPORT
Kubernetes version (use kubectl version
):
Client Version: version.Info{Major:“1”, Minor:“8”, GitVersion:“v1.8.2”, GitCommit:“bdaeafa71f6c7c04636251031f93464384d54963”, GitTreeState:“clean”, BuildDate:“2017-10-24T19:48:57Z”, GoVersion:“go1.8.3”, Compiler:“gc”, Platform:“darwin/amd64”}
Server Version: version.Info{Major:“1”, Minor:“8+”, GitVersion:“v1.8.2-gke.0”, GitCommit:“52ea03646e64b35a5b092ab32bb529400c296aa6”, GitTreeState:“clean”, BuildDate:“2017-10-24T23:31:18Z”, GoVersion:“go1.8.3b4”, Compiler:“gc”, Platform:“linux/amd64”}
Environment:
- Cloud provider or hardware configuration: gke
- OS (e.g. from /etc/os-release): macos 10.12.6
What happened:
kubectl get all
does not list all resources in a namespace.
What you expected to happen:
As a user performing kubectl get all
I expect to see all objects in the current context, including limits.
How to reproduce it (as minimally and precisely as possible):
kubectl create namespace tmp
kubectl create -f https://k8s.io/docs/tasks/administer-cluster/memory-defaults.yaml --namespace=tmp
kubectl get all --namespace tmp
namespace "tmp" created
limitrange "mem-limit-range" created
No resources found.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 96
- Comments: 94 (27 by maintainers)
Links to this issue
Commits related to this issue
- template-processors/base/bin: don't try deleting ComponentStatus objects This commit works around a problem mentioned in https://github.com/kubernetes/kubectl/issues/151#issuecomment-562578617: ... — committed to akavel/eunomia by deleted user 4 years ago
- template-processors/base/bin: don't try deleting ComponentStatus objects This commit works around a problem mentioned in https://github.com/kubernetes/kubectl/issues/151#issuecomment-562578617: ... — committed to akavel/eunomia by deleted user 4 years ago
- Fix describe-kubernetes-objects role According to [0] kubectl get all -A does not include all types (e.g. configmaps) and is going to be deprecated. Instead of getting all objects with one kubectl re... — committed to airshipit/airshipctl by aostapenko 4 years ago
- Improve post-mortem logging, list resources better List all available API resources in post mortem, vs only the subset covered by `kubectl get all`. This is the recommended practice: github.com/kube... — committed to dfarrell07/shipyard by dfarrell07 3 years ago
- Improve post-mortem logging, list resources better List all available API resources in post mortem, vs only the subset covered by `kubectl get all`. This is the recommended practice: github.com/kube... — committed to dfarrell07/shipyard by dfarrell07 3 years ago
- Improve post-mortem logging, list resources better List all available API resources in post mortem, vs only the subset covered by `kubectl get all`. This is the recommended practice: github.com/kube... — committed to submariner-io/shipyard by dfarrell07 3 years ago
kubectl get all --namespace tmp
is wrong, you may usekubectl get all --n tmp
Why is this closed? Some complex xargs stuff does not mitigate the fact at “all” is indeed a falsehood that does not return all objects.
kubectl api-resources
enumerates the resource types available in your cluster.this means you can combine it with
kubectl get
to actually list every instance of every resource type in a namespace:/close
Try -
kubectl get all --all-namespaces
I’d like to see a documentation improvement, as well as a new ‘type’ to use to actually show all resources in a namespace, as the current meaning of
all
is both unintuitive and not documented anywhere. Just fixing kubectl wouldn’t help users figure out what’s going on for older versions, so I think a new name (everything
?) would be helpful for retaining consistency with older client versions.Currently I know that
all
doesn’t refer to the following types of resources:--all-namespaces
it might be useful to include these): clusterrolebindings, clusterroles, etc.all
does refer to the following types of (namespaced) resources:--show-all
This is only a partial list, as I have no way of knowing what are kinds of resources are listed by
all
I think there needs to be better documentation around resources in general, and a better explanation of the magic
all
resource pseudo-type.its funny how you implement something sloppy and then you have an issue open for 3 years where you make all sorts of excuses why this should stay this way.
all
will not be extended because of compatibility concerns, and is not referenced in help any longer because it is misleading, as you point outThis also has the disadvantages of not only being unintuitive, but also slow as hell …
Crazy… Instead of fixing the buggy command they removed it from documentation.
@fabianofranz: Yes, limits are covered there (Rule 2: No namespace admin level resources (limits, quota, policy, authorization rules)).
This leaves me frustrated though:
kubectl help get
describeskubectl get all
asList all resources with different types.
so I think I am right to expect all resources to be listed.kubectl get all --all-namespaces
will list the resources from all the namespace
This really has the capacity to trip-up new (and old) users alike in interesting and frustrating ways. If
all
isn’tall
and never will beall
again, surely it has to be deprecated? Is it actually a compatibility issue - is this command porcelain for scripting?Example of getting caught:
kubectl get all --namespace ns1
(nothing)kubectl get pvc --namespace ns1
(1 pvc is listed)Ah - so
helm delete
didn’t remove my persistent volumes … I wishall
had told me that.Meanwhile I worked around the problem by using ketall (it can be installed via krew).
I know, this isn’t what you’re looking for but it’s not so bad. I hope you’ll find it useful anyway. 😃
/reopen
@stewart-yu: Double dash and short form (
kubectl get all --n tmp
) doesn’t work!Both variants below do work:
kubectl get all --namespace tmp
kubectl get all -n tmp
You can look that up in
kubectl options
:/close
My current situation is that I have a cluster with some namespaces, I try to delete a namespace and it’s stuck in
Terminating
state. I know this situation is mentioned in other issues here, but unfortunately those are closed too. I’m not going to ask how to solve this problem, instead I want to invest time and understand what’s going on, if same problem happened with a resource in Linux operating system I could understand why exactly it’s happening by reading logs and running commands and reading their outputs and wouldn’t ask Linus Torvalds about it in Linux git repository. In order to decide that kubernetes is a reliable tool for my company I need to make sure same thing can happen in kubernetes too, I wanna make sure someone can reach to a point with kubernetes that he can solve the unknown problems by reading logs, seeing states of resources, etc instead of creating issues in kubernetes repository and waiting for someone to reply. I think for kubernetes to be considered mature it should be self diagnosable (like Linux with its logs and commands, Python with its shell and pdb, JS with devtools, etc).So I think it should be in high priority to:
For my mentioned problem I thought maybe something in the undeletable namespace is pending another resource in another namespace so I wanted to see all resources in the default namespace to see if my theory makes sense or not. Not being able to list all resources (including custom resources) is really annoying stopped me and a problem that could probably solved by myself by investing time is now only solvable by either opening an issue here and waiting unknown time for someone to answer or invest much more time reading the source code of kubernetes and compile it with debug directives and see what’s going on.
@davidbIQ there are plenty of different answers in this thread, if you can’t find a suitable one, then script one for your self.
@HartS When running
kubectl get
I’m shown a list of resource types.That might be a decent place to start for documentation.
For reference I got the below against my v1.10.0 Kube setup.
that also doesn’t work:
Is there some other literate way to “verb” all by label?
@smarterclayton can you provide a link to the issue?
I’m not concerned about kubernetes not deleting a namespace when I issue
kubectl delete namespace <namespace>
. I’ve never seen that happen.I’m concerned about the user interface issue. I expect to be able to list everything (preferrably via
kubectl get all
, but an alternative command might be ok aswell), so I can make an informed decision.To me this is the same as being the admin of a linux box without
ls -a
. On that box I might forget to backup everything that is hidden (including my .profile, and .ssh private keys). In both cases (kubectl and linux box) I’m setting myself up for desaster because it becomes very likely that I loose data at some point in the future.@qgeffard the short answer is that the “all” special keyword was explicitly removed because it didn’t play well with the way
kubectl
interacts with CRD categories.Long answer, read on:
kubectl get
has essentially 2 modes:kubectl get <concrete kind>
returns a list of all objects of a given kind (e.g.kubectl get pod
)kubectl get <any word>
is a fallback which returns all objects of a given category (documentation)For example, consider that you install a Kubernetes-native solution such as Istio (example picked semi-randomly, simply because it is popular). Now imagine that Istio uses the mechanism of categories mentioned above to tag each of their CRD with the “istio” category. You can now list all Istio-related objects with
kubectl get istio
. Neat!Now imagine that some of those category names, like “all”, are reserved. You end up in a situation where a given keyword can have not one, not two, but three (!) different meanings. This is likely to confuse users and CRD authors alike so, instead of reserving some special keywords, it was decided that no category should be treated differently (in other words, “all” is a perfectly valid category as well).
Thankfully, plugins are first-class citizens in
kubectl
, so special and opinionated features such as the defunctkubectl get all
could be / were encouraged to be supported by community-maintained plugins instead. Using the official Krew plugin manager, it is even super easy to search and install such plugins, regardless of the platform you use.I hope I helped better understand the “why” 🙏
I know it’s a old discussion, but why I arrived here is very simple: I was searching for a simple way to list all the objects created in a namespace, hence, I have found the existence of the
all
keyword.This
all
keyword really makes sens for me. Then I discover thatall
isn’t listing all kind of objects… Hence my discovery of this ticket!Honnestly, it’s hard to understand why this keyword was removed from the documentation and never implemented to fully return all kind of objects.
There is no simple alternative.
Agreed on the deprecation comment.
Perhaps instead of breaking backwards compatibility we could allow a glob syntax, so for example
*role*
would returnrole
,rolebinding
,clusterrole
,clusterrolebinding
and*
would return everything. I’m glad thatall
is no longer a resource, so perhaps we can with this approach distinct between a resource type and syntax.Soo, can we just close this for now, the answers are already answered through this thread. Thanks
On Wed, 22 Apr 2020, 22:20 Antoine Cotten, notifications@github.com wrote:
A much faster alternative to using
xargs -n1
would be something like this:and if you put that into a file called
kubectl-everything
that has the execute bit and sits somewhere in your path, then you can even dokubectl everything -n mynamespace
to list all resources in a specific namespace.@soltysh: Closing this issue.
In response to this:
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.
A nifty trickery and all that I’d certainly go for, but api-resources doesn’t exist in kubectl < 1.11. I’m not sure why there’s a debate about the definition of all. All is all, save for any boundaries around security.
I will fix it ASAP
I’m going to jump in here and provide feedback that while the
xargs
stuff is better than nothing, it’s not an option on Windows. And yes, I am aware there are other workaround with Powershell.The fact this has been broken for several years and it’s just being punted from release to release is immensely frustrating. Replace or remove the
all
functionality but leaving it languish like this is a terrible user experience.in 1.11, the help text no longer references
all
, and instead refers to a newkubectl api-resources
command which lists all resources the server you are currently speaking to has:or
Is there a reason on why the kubectl get-all is not integrated to the native/vanilla kubectl and also documented?
Snippet listing all resources as in @oudream’s comment, with
$()
speedup from @bdowling’s comment, and with another simplification replacingtr|sed
withpaste
:kubectl get $(kubectl api-resources --verbs=list -o name | paste -sd, -) --ignore-not-found --all-namespaces
kubectl api-resources -o name | xargs -I {} kubectl get {} --show-kind --ignore-not-found
It’s not a 100% solution, but for me works the following
kgetall='kubectl get namespace,replicaset,secret,nodes,job,daemonset,statefulset,ingress,configmap,pv,pvc,service,deployment,pod --all-namespaces'
and just callkgetall
But obviously I expected that behavior fromkubectl get all --all-namespaces
in the first place.Just to add a workaround for:
Error: uninstallation completed with 1 error(s): could not get apiVersions from Kubernetes: could not get apiVersions from Kubernetes: unable to retrieve the complete list of server APIs: external.metrics.k8s.io/v1beta1: the server is currently unable to handle the request
run:
kubectl delete apiservice v1beta1.external.metrics.k8s.io
Credits go to: https://twitter.com/abhi_tweeter
@liggitt
This works for me
kubectl api-resources --verbs=list --namespaced -o name | xargs -n 1 kubectl get --show-kind -A 2>/dev/null
Ignore errors
It sounds like the most reasonable time to remove the “all” category would be when the horizontalpodautoscalers formally announce their intent for v2? That way it wouldn’t get blocked for an unknown amount of time with v2 resources, then blocked on v3, etc.
I guess in all of this, what is the end result realistically going to be? Would just ensuring “all” returns everything be easier than trying to get the category deprecated? This limbo area is miserable from a user experience standpoint.
@liggitt @seans3 any updates on getting this functionality removed?
kubectl get all
is deceptive and could lead to issues with it’s use.It should be deprecated and removed or it should be enhanced to actually list all resources in a namespace.
At the very least when the current implementation is used it should display a warning.
The
all
alias won’t be removed for compatibility reasons but has been removed from command help for several releases. I agree it should not be promoted as it is confusing.The
xargs
based command resulted in multipleList
resources. The following seems faster, and results in oneList
of resources.This plugin seems to be nice and do the work! My question is more why this kind of tool isn’t integrated by default in kubectl?
Yes, agreed. Doesn’t really matter where you put the -n arg
kubectl get -n tmp po,sts,svc,whatever
also worksNot that it matters in here, but just a side-note, I think it’s easier to just add -A instead of –all-namespaces
kubectl get all -A
@seans3 @liggitt we should probably just start the deprecation process for this?
@oudream thanks for that. Slight improvement since most use cases of this is dealing with a particular NAMESPACE …
kubectl -n NAMESPACE api-resources –namespaced=true -o name | xargs --verbose -I {} kubectl -n NAMESPACE get {} --show-kind --ignore-not-found
or another variant:
kubectl get $(kubectl api-resources --namespaced=true -o name | tr '\n' ,| sed 's/,$//') --ignore-not-found
Same issue here. Its returning only deployments, replicasets and pods
@davidbIQ I’m not a Kubernetes contributor, but this issue is closed and most likely not monitored by anyone.
Is anything stopping you from using the
kubectl get-all
plugin, as suggested in https://github.com/kubernetes/kubectl/issues/151#issuecomment-594978672? What you are trying to achieve is the exact reason why those plugins exist.@dene14 “Migrate releases from helm2 to helm3” sounds very much off topic to me.
@rkand4 this is a question for StackOverflow or discuss.kubernetes.io.
The short answer is no. You have to range over all the APIs returned by
getAPIVersions
, list the resources inside each returned API (only thepreferredVersion
of each API), and finally get the objects for these resources in each namespace. There is no shortcut.Ref: https://github.com/kubernetes/community/blob/master/contributors/devel/kubectl-conventions.md#rules-for-extending-special-resource-alias---all
We may want to explain
all
in the help text.upvote to fix
@cah-prakash-kalaiarasu01 and @micktg: that only lists a very small subset of resources.
To list all resources, like the issue’s title suggests, see https://github.com/kubernetes/kubectl/issues/151#issuecomment-594978672
There are some rules about which resources must fall under “all”, take a look here. Are the resources you want covered there?
Because one cannot install anything on the CKAD exam.
@kesor Note however that under MacOS one has to add a
-
parameter topaste
(or install the GNU version of paste), because defaulting to stdin isn’t implied in BSD paste.If someone still suffers from that problem, please check this script: https://gist.github.com/dene14/7253685cdedde2b6d16e8fc1df450d4f
For some reason when I add a label selector that should not match anything to the command @akavel provided, it returns 3 ComponentStatus items
@sarunask that’s a terrible idea, this method bypasses finalizers so it leaves all the objects belonging to the namespace inside your cluster.
See kubernetes/kubernetes#73405 and https://github.com/kubernetes/kubernetes/issues/60807#issuecomment-429754733 instead.
@liggitt does
kubectl api-resources
replace the functionality as well or this just meanskubectl get all
is going to be deprecated and there will not be any support for searching labels in a namespace?My use case is the same as the issue:
which doesn’t return secrets, for example:
kubectl version
: