Kubectl: Need a real "get-all" command

Created on 29 Aug 2018  路  29Comments  路  Source: kubernetes/kubectl

FEATURE REQUEST:

Add a get-all command that really shows all objects, with some flags to filter on certain types (namespaced vs non-namespaced, etc).

Similarly, the dashboard should have a mode to show all resources (again, dashboard does not show networkpolicy objects, not even in pod descriptions to say "this pod is selected by this networkpolicy object". But dashboard improvement should be implemented separately, as the most important and urgent one is the kubectl new command.

Kubernetes version (use kubectl version):

1.11.2

What happened:

kubectl get all only shows a small subset of kubernetes objects in a cluster, and there does not seem to be a command to get all objects (secrets, network policies, etc). This caused me hours of wasted time because I was trying to replicate a deployment object from another cluster into a new cluster, and didn't see that there was a networkpolicy needed for the service to expose that deployment.

What you expected to happen:

That kubect get all would show all, not just a small number of types of resources.

How to reproduce it (as minimally and precisely as possible):

Create a networkpolicy then do kubectl get all, it doesn't show up. However, it does show up with kubectl get netpol and kubectl api-resources -o name | xargs -t -n 1 kubectl get --ignore-not-found --show-kind | grep SOMETHING_IN_NAME

arekubectl kinfeature sicli triagneeds-information

Most helpful comment

I firmly believe that this functionality belongs in the core. It is unrealistic to say that you are displaying all kubernetes resources and it is misleading.

All 29 comments

/kind feature
/sig cli
/area kubectl
/priority P3

This functionality sounds like something that'd be great to implement as a plugin

Where would I start? I know some Go and I have lots of software dev experience so that part is not a problem, it's more the logistics : how do I mark that I'm working on this so people know, where do I publish it for peer review, for downloading, etc. I found https://kubernetes.io/docs/tasks/extend-kubectl/kubectl-plugins/, are there other links that I should look at?

@schollii

Where would I start?

I am currently updating the docs for plugins, so that they are up to date with the current plugin system: https://github.com/kubernetes/website/pull/10259, see https://deploy-preview-10259--kubernetes-io-master-staging.netlify.com/docs/tasks/extend-kubectl/kubectl-plugins/ (while that PR merges) for an accurate doc on the current state of plugins.

You can also take a look at https://github.com/kubernetes/sample-cli-plugin for a detailed example of writing a plugin in Go.

how do I mark that I'm working on this so people know, where do I publish it for peer review, for downloading, etc

Although there's no official registry or repo where you would formally declare your work on a plugin (for now), you are always welcome to host it on a repo of your own, and link to it in the slack channel for SIG-CLI, as well as request peer review there.

I'd be happy to help review it as well. Feel free to reach out on Slack with any questions.
Thanks

@schollii plugin documentation has now been updated. You can find a guide for writing plugins under the new mechanism at: https://kubernetes.io/docs/tasks/extend-kubectl/kubectl-plugins/#writing-kubectl-plugins

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

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 rotten

@schollii Have a look at https://github.com/corneliusweig/ketall . It is also available via krew, so that it can be installed via kubectl krew install get-all. Please raise an issue, if this doesn't fully meet your requirements.

quick hack: kubectl get $(kubectl api-resources| awk '{ print $1 }'|grep -v "NAME"|xargs|sed -e 's/ /,/g')

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

I firmly believe that this functionality belongs in the core. It is unrealistic to say that you are displaying all kubernetes resources and it is misleading.

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 rotten

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

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

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

@fejta-bot: Closing this issue.

In response to this:

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

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.

/reopen

This one of the the weirdest, most confusing things about learning k8s; the fact that "get all" means "get a few random things" . If "all" doesn't mean "all," rename it "common" or "basic" something.

please /reopen

Note that you can pass a comma-separated list of resource kinds to the get command:

$ kubectl get deployments,services,ingresses -l app=myapp

You can use the following command (no xargs required) to get literally all resource types:

$ kubectl get $(kubectl api-resources --verbs=list --namespaced -o name | paste -sd ',') -l app=myapp

@bendavis78 nice but I don't want to have to type that every time, nor create an alias for this on every system where I use kubectl. kubectl get all -l app=myapp should do the go-equivalent of your solution.

Given the API already exists, the change should be simple. I don't mind doing it I just need a go-ahead, and a little guidance. The api-resources command can likely be called via https://github.com/kubernetes/kubectl/blob/3082866d52a22b838a02acb0f1309b62d9b5433b/pkg/cmd/apiresources/apiresources.go#L137. For the get command, looks like I would edit https://github.com/kubernetes/kubectl/blob/master/pkg/cmd/get/get.go. In particular, somewhere in the vicinity of https://github.com/kubernetes/kubectl/blob/596d7b0ffffd963af1b995fea599ad49d9b2a046/pkg/cmd/get/get.go#L467 I would do the following:

  • call RunAPIResources() on a APIResourceOptions that equates to --verbs=list --namespaced -o name
  • loop over the types received; for each one, call the Run() of GetOptions with the same options as given to the get command, but minus the all type
  • aggregate the output and then print it (probably use the --all-namespaces as guidance since it probably does basically the same logic just for namespaces instead of resource types)

Am I getting this right?

I'm not sure the historical context on this one but we can reopen until we get an official word out.

/remove-lifecycle rotten
/remove-priority P3
/triage needs-information
/reopen

@eddiezane: Reopened this issue.

In response to this:

I'm not sure the historical context on this one but we can reopen until we get an official word out.

/remove-lifecycle rotten
/remove-priority P3
/triage needs-information
/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.

Following up..

kubectl get all is a legacy command and is actually implemented with a hardcoded server side list that is not easy to maintain. There is potential that it will be removed in the future and therefore will not be expanded upon or improved at this time.

We recommend using ketall which can be installed standalone or via krew.

/close

@eddiezane: Closing this issue.

In response to this:

Following up..

kubectl get all is a legacy command and is actually implemented with a hardcoded server side list that is not easy to maintain. There is potential that it will be removed in the future and therefore will not be expanded upon or improved at this time.

We recommend using ketall which can be installed standalone or via krew.

/close

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.

Wow. You have to install extra stuff to do something this basic? Bizarre. If the existing command is poorly implemented, and doesn't provide the results people expect, why can't it be re-implemented correctly?

I was going to ask exactly that. I've outlined a solution, plus we could adapt code from ketall.

/reopen please

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ZhilinS picture ZhilinS  路  5Comments

pwittrock picture pwittrock  路  6Comments

drpaneas picture drpaneas  路  3Comments

mnussbaum picture mnussbaum  路  6Comments

cbluth picture cbluth  路  6Comments