liveBook · Manning

Kubectl get

As explained in Kubernetes in Action, Second Edition

kubectl get is a kubectl command that retrieves Kubernetes objects of a specified type from the API.

`kubectl get` retrieves Kubernetes objects of a specified type from the cluster API. Use it for a quick list or status check: `kubectl get nodes` shows the cluster’s nodes, while `kubectl get pod kiada` checks one pod. The default columns show only a summary. section 3.2.3 section 5.2.3

Check a running pod

Run `kubectl get pod kiada`. A result showing `READY 1/1` and `STATUS Running` confirms the pod is running, but does not show much else about it. section 5.2.3

Choose the object type for the question at hand: `kubectl get events` lists Event objects, `kubectl get services` lists Services, and `kubectl get replicasets` lists ReplicaSets. The shorter names `ev`, `svc`, and `rs` also work. Events are separate objects, not fields inside the objects they describe, and are deleted after a retention period. section 4.3.1 section 14.1.2 section 11.1.2

When the default summary is not enough:

  • Add `-o wide` for more columns. For example, it can show a Service’s label selector or a ReplicaSet’s selector, container names, and images. section 11.1.2 section 14.1.2
  • Use `kubectl describe` for a fuller, readable view, or `-o yaml` or `-o json` for the object definition. The object list has no option to display annotations; inspect them with `describe` or in the definition instead. section 3.2.3 section 7.5.3
  • Filter pod listings with a label selector. To find pods matching a ReplicaSet’s selector, use a command such as `kubectl get po -l app=kiada,rel=stable`; there is no direct command to list a ReplicaSet’s pods. section 14.1.2

Check a ReplicaSet’s replica counts

`kubectl get rs kiada` can show `DESIRED 5`, `CURRENT 5`, and `READY 5`. These columns let you compare the requested replica count with the current and ready counts without opening the full object. section 14.1.2

How Kubernetes in Action, Second Edition covers it

How deep it goes
Defines API retrieval and demonstrates summary columns, wider output, and filtering; defers fuller object inspection to `kubectl describe` or object definitions.
Examples
Shows node and pod status listings, Event listings, ReplicaSet replica counts, selector-filtered pods, and wide Service output.
What it assumes
Assumes `kubectl` is installed and configured to talk to a cluster; defines object retrieval from the API.
What you can do after
Operate/configure it to check object status, select matching pods, and request additional columns before choosing a more detailed inspection command.
How it connects
Connects API objects and status checks with label selectors, ReplicaSets, Services, Events, and `kubectl describe`.

Also explained in

Compare how 2 books explain kubectl get →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Kubernetes in Action, Second Edition. The section links point to the parts of the book it draws on.