Chapter 3. Learning to Use the Kubernetes Client

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.

3.1 Listing Resources


You want to list Kubernetes resources of a certain kind.


Use the 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

Note that 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:

  • configmaps (aka cm)

  • daemonsets (aka ds)

  • deployments (aka deploy)

  • endpoints (aka ep)

  • events (aka ev)

  • horizontalpodautoscalers (aka hpa)

  • ingresses (aka ing)

  • namespaces (aka ns)

  • nodes (aka no)

  • persistentvolumeclaims (aka pvc)

  • persistentvolumes (aka pv)

  • pods (aka po)

  • replicasets (aka rs)

  • replicationcontrollers (aka rc)

  • resourcequotas (aka quota)

  • serviceaccounts (aka sa)

  • services (aka svc)

3.2 Deleting Resources


You no longer need resources and want to get rid of them.


Use the delete ...

Get Kubernetes Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.