LinuxCommandLibrary

kubectl-get

Retrieve information about Kubernetes resources

TLDR

Get all namespaces in the current cluster

$ kubectl get [[ns|namespaces]]
copy

Get nodes in a specified namespace
$ kubectl get [[no|nodes]] [[-n|--namespace]] [namespace]
copy

Get pods in a specified namespace
$ kubectl get [[po|pods]] [[-n|--namespace]] [namespace]
copy

Get deployments in a specified namespace
$ kubectl get [[deploy|deployments]] [[-n|--namespace]] [namespace]
copy

Get services in a specified namespace
$ kubectl get [[svc|services]] [[-n|--namespace]] [namespace]
copy

Get other resources
$ kubectl get [persistentvolumeclaims|secret|...]
copy

Get all resources in all namespaces
$ kubectl get all [[-A|--all-namespaces]]
copy

Get Kubernetes objects defined in a YAML manifest file
$ kubectl get [[-f|--filename]] [path/to/manifest.yaml]
copy

SYNOPSIS


kubectl get (TYPE | TYPE/NAME | TYPE NAME) [flags]

Examples:
kubectl get pods
kubectl get deployments my-app -o yaml
kubectl get all -A

PARAMETERS

TYPE
    The resource type to retrieve (e.g., pod, service, deployment, node, namespace, ingress).

NAME
    The specific name of the resource to retrieve (optional).

-o, --output=FORMAT
    Output format. Common options include json, yaml, wide, name, custom-columns.

-n, --namespace=NAME
    If present, the namespace scope for this request.

-A, --all-namespaces
    If present, list the requested object(s) across all namespaces.

-l, --selector=KEY=VALUE
    Selector (label query) to filter on, supports =, ==, !=, in, notin.

-w, --watch
    After listing, start watching for changes, providing a continuous update stream.

--show-labels
    When printing, show all labels as the last column (default false).

--sort-by=PATH
    Sort list output using this JSONPath expression.

DESCRIPTION

The kubectl get command is a fundamental and frequently used tool within the Kubernetes command-line interface (CLI). Its primary function is to retrieve and display information about various resources in a Kubernetes cluster. Users can specify the type of resource (e.g., pods, services, deployments, namespaces, nodes) they wish to view, and optionally filter by name, labels, or namespace. This command is crucial for observing the current state of the cluster, troubleshooting issues, and verifying deployments. It supports multiple output formats, including plain text, YAML, JSON, and wide (more details), making it highly versatile for both human readability and machine processing. Whether you need a quick overview of running pods or detailed configuration of a service, kubectl get is the go-to command for cluster introspection.

CAVEATS


When using kubectl get on a large cluster, especially with --all-namespaces or retrieving detailed formats like yaml or json for many resources, the output can be extensive and may impact performance or be difficult to parse visually. Always specify the resource type and narrow down with names or selectors when possible to get more focused results.

FILTERING BY LABELS

You can use the -l or --selector flag to filter resources based on their labels. For example, kubectl get pods -l app=nginx will show only pods with the label app=nginx, which is incredibly useful for managing complex deployments.

CUSTOM COLUMNS

The --output=custom-columns and --output=custom-columns-file flags allow users to define their own output columns using JSONPath expressions, providing highly customizable views of resources. This enables users to extract specific data points vital for their workflows.

HISTORY


The kubectl get command has been a core component of Kubernetes from its early days, essential for observing and managing cluster state. As Kubernetes matured, get evolved with new resource types and improved output options. Its consistent syntax and expanding capabilities reflect the project's commitment to providing robust and observable cluster management, making it an indispensable tool for every Kubernetes user.

SEE ALSO

kubectl describe(1), kubectl apply(1), kubectl delete(1), kubectl logs(1)

Copied to clipboard