An Alternative to the ‘kubectl get all’ Command.

An Alternative to the ‘kubectl get all’ Command.

Have you ever wondered how to get a more detailed and complete view of resources in an OpenShift namespace? The standard oc get all command is helpful, but it is unable to display all the resources in namespaces, only returning a basic set of resource types. Today, I want to introduce you to an alternative that allows for a full list of listable resources.

The command I want to share with you is:

kubectl get $(kubectl api-resources --namespaced=true --verbs=list -o name | awk '{printf "%s%s",sep,$0;sep=","}') --ignore-not-found -n ${NAMESPACE} -o=custom-columns=KIND:.kind, --sort-by='kind'

Although it may look complex at first glance, it’s quite simple when broken down into parts. The command consists of three main segments.

  1. First off, kubectl api-resources --namespaced=true --verbs=list -o name calls a list of all resources that are namespace-related and listable. The result is returned in name format.
  2. The next segment, awk '{printf "%s%s",sep,$0;sep=","}', is an AWK script that processes the result of the previous command into a comma-separated list.
  3. The final command, kubectl get $(...) --ignore-not-found -n ${NAMESPACE} -o=custom-columns=KIND:.kind, --sort-by='kind', utilizes the resultant format from the previous commands to fetch resources from a specified namespace, denoted by the ${NAMESPACE} variable. It sets the --ignore-not-found parameter to ignore resources that are not found. The -o=custom-columns=KIND:.kind, option specifies the output format to only show the kind of resource and its name. Additionally, the --sort-by='kind' flag serves to sort the results by the kind of resource.

This command is particularly useful when you want to understand what resources are available in your namespace. It allows for the display of a full list of listable resources, as opposed to the kubectl get all command which only returns a basic set of resource types.

However, bear in mind that this command is not a one-size-fits-all solution. In the case of a large number of resources in a namespace, the results can be overwhelming. Nevertheless, it is a powerful tool that allows for a more comprehensive picture of what’s happening in your OpenShift cluster.

So the next time you need a more complete picture of resources in an OpenShift namespace, consider utilizing this command. It might just be the tool you need to better understand and manage your infrastructure.

More useful commands:

Dodaj komentarz

Twój adres e-mail nie zostanie opublikowany. Wymagane pola są oznaczone *

Witryna wykorzystuje Akismet, aby ograniczyć spam. Dowiedz się więcej jak przetwarzane są dane komentarzy.