LinuxCommandLibrary

kubectl-api-resources

List available Kubernetes API resources

TLDR

Print the supported API resources

$ kubectl api-resources
copy

Print the supported API resources with more information
$ kubectl api-resources [[-o|--output]] wide
copy

Print the supported API resources sorted by a column
$ kubectl api-resources --sort-by [name]
copy

Print the supported namespaced resources
$ kubectl api-resources --namespaced
copy

Print the supported non-namespaced resources
$ kubectl api-resources --namespaced=false
copy

Print the supported API resources with a specific API group
$ kubectl api-resources --api-group=[api_group]
copy

SYNOPSIS

kubectl api-resources [flags]

PARAMETERS

--api-group=<string>
    Filters the output to show only resources belonging to the specified API group (e.g., 'apps', 'batch').

--api-version=<string>
    Filters the output to show only resources belonging to the specified API version (e.g., 'v1', 'apps/v1').

--cached=<bool>
    If true, uses the cached list of API resources instead of fetching directly from the API server. Defaults to false.

--namespaced=<bool>
    If true (default), only namespaced resources are returned. If false, only non-namespaced (cluster-scoped) resources are returned.

--no-headers
    Disables printing column headers in the output.

--output=<string>
    Output format. Can be 'wide' for more details or 'name' to show just resource names.

--output-group-version
    Outputs only the API group and version for each resource.

--output-verbs
    Outputs the supported verbs (e.g., 'get', 'list', 'create') for each resource.

--sort-by=<string>
    Sorts the list of API resources by a specified field (e.g., 'name', 'kind', 'namespaced', 'verbs').

--verbs=<string>
    Filters the output to show only resources that support the specified verbs (e.g., 'get,list,watch').

--context=<string>
    The name of the kubeconfig context to use for the command.

--kubeconfig=<string>
    Path to the kubeconfig file to use for CLI requests, overriding the default location.

--server=<string>
    The address and port of the Kubernetes API server to connect to.

DESCRIPTION

The kubectl api-resources command is a crucial tool for understanding the landscape of available resources within a Kubernetes cluster. It provides a comprehensive list of all API resources that the Kubernetes API server exposes, including built-in resources like Pods, Deployments, and Services, as well as any
Custom Resource Definitions (CRDs) installed in the cluster. For each resource, it displays its NAME, any SHORTNAMES (aliases for easier command-line usage), its associated APIVERSION (e.g., apps/v1, v1), whether it is NAMESPACED (true for most application resources, false for cluster-level resources like Nodes), and its KIND. This command is invaluable for developers and administrators to quickly identify available APIs, verify resource existence, debug configuration issues, or learn about the specific API group and version to use when crafting YAML manifests or interacting with the cluster via the kubectl CLI.

CAVEATS

This command relies on connectivity and authentication to a Kubernetes API server.
Users must have appropriate
Role-Based Access Control (RBAC) permissions to discover API resources.
The output can be extensive in clusters with numerous
Custom Resource Definitions (CRDs).
Using the --cached flag may return outdated information if the API server's available resources have recently changed.

TYPICAL USE CASES

kubectl api-resources is highly useful for:
Discovering available resources: Quickly find out what standard and custom resources are deployed in a cluster.
Debugging 'resource not found' errors: Verify the correct name, API group, and version of a resource.
Learning about API structure: Understand which resources are namespaced versus cluster-scoped.
Crafting YAML manifests: Identify the correct apiVersion and kind fields for new resources.

HISTORY

The kubectl command-line tool is the primary interface for interacting with Kubernetes clusters, and the api-resources subcommand has been a fundamental part of its discovery capabilities since the early days of Kubernetes. As the Kubernetes ecosystem grew, especially with the introduction and widespread adoption of
Custom Resource Definitions (CRDs), the need for a reliable and comprehensive way to discover all available API objects became even more critical. kubectl api-resources was developed to address this, providing a dynamic view of the cluster's API surface, adapting to new features and custom extensions deployed by users and operators.

SEE ALSO

kubectl get(1), kubectl explain(1), kubectl describe(1), kubectl api-versions(1), kubectl get crd(1)

Copied to clipboard