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 [NAME_PREFIX] | TYPE/NAME | NAME | -f FILENAME | -R) [flags]

PARAMETERS

-A, --all-namespaces
    Display resources from all namespaces; cannot use with --namespace

--allow-missing-template-keys
    Ignore missing fields in output templates

--chunk-size int
    Chunk large lists into smaller batches

--field-selector string
    Filter by field selectors like metadata.name=my-pod

-h, --help
    Display help for get

-k, --kustomize string
    Process kustomization directory and use output

-L, --label-columns strings
    Display specified labels in tabular output

-l, --selector string
    Label selector to filter resources (e.g., app=myapp)

--no-headers
    Omit headers in output

-n, --namespace string
    Specify namespace for resources

-o, --output string
    Output format: json, yaml, wide, name, jsonpath, go-template, template, custom-columns

--raw string
    Raw URI to request directly from API server

-R, --recursive
    Recursively process directories with -f

--request-timeout duration
    Timeout for server requests

--server-side
    Use server-side filtering for large queries

--show-kind
    Display object kind in output

--show-labels
    Display all labels

--sort-by string
    Sort list by JSONPath expression

--template string
    Go template for custom output

DESCRIPTION

The kubectl get command is a fundamental tool in the Kubernetes CLI for retrieving and listing resources from a cluster. It fetches information about objects such as pods, services, deployments, nodes, namespaces, and more, displaying them in a human-readable tabular format by default.

Users specify the resource type (e.g., pods, svc for services) followed optionally by a name prefix or specific name. It supports listing resources across namespaces or recursively within namespaces. Output can be customized with formats like wide, JSON, YAML, or custom templates for scripting and automation.

Common use cases include monitoring pod status, checking service endpoints, verifying deployments, or debugging cluster state. Flags enable filtering by labels, fields, or selectors, sorting results, and suppressing headers. It respects RBAC permissions, showing only accessible resources.

When combined with watch flag (via -w), it streams live updates, ideal for real-time observation. For large clusters, chunking prevents overload. Overall, kubectl get provides quick visibility into cluster health and configuration, essential for operators and developers managing containerized workloads.

CAVEATS

Requires valid kubeconfig and cluster access; respects RBAC; may timeout on large lists without --chunk-size; output formats like JSON require jq or similar for parsing.

EXAMPLES

kubectl get pods
kubectl get pods -n kube-system -o wide
kubectl get all -l app=myapp --all-namespaces
kubectl get nodes --show-labels

RESOURCE TYPES

Common types: po (pods), svc (services), deploy (deployments), no (nodes), ns (namespaces), all (everything)

HISTORY

Part of kubectl since Kubernetes v1.0 (2014), developed by Google and donated to CNCF. Evolved with API changes; server-side apply added in v1.13; chunking in v1.9 for scalability.

SEE ALSO

kubectl describe(1), kubectl apply(1), kubectl list(1)

Copied to clipboard