This chapter gathers recipes around the basic usage of the Kubernetes command-line interface (CLI),
kubectl. See Chapter 1 for how to install the CLI tool; for advanced use cases, see Chapter 6, where we show how to use the Kubernetes API.
You want to list Kubernetes resources of a certain kind.
get verb of
kubectl along with the resource type. To list all pods:
$ kubectl get pods
To list all services and deployments:
$ kubectl get services,deployments
To list a specific deployment:
$ kubectl get deployment myfirstk8sapp
To list all resources:
$ kubectl get all
kubectl get is a very basic but extremely useful command to get a quick overview what is going on in the cluster—it’s essentially the equivalent to
ps on Unix.
Many resources have short names you can use with
kubectl, sparing your time and sanity. Here are some examples:
You no longer need resources and want to get rid of them.