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
Problem
You want to list Kubernetes resources of a certain kind.
Solution
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.
Tip
Many resources have short names you can use with kubectl
, sparing your time and sanity. Here are some examples:
-
configmaps
(akacm
) -
daemonsets
(akads
) -
deployments
(akadeploy
) -
endpoints
(akaep
) -
events
(akaev
) -
horizontalpodautoscalers
(akahpa
) -
ingresses
(akaing
) -
namespaces
(akans
) -
nodes
(akano
) -
persistentvolumeclaims
(akapvc
) -
persistentvolumes
(akapv
) -
pods
(akapo
) -
replicasets
(akars
) -
replicationcontrollers
(akarc
) -
resourcequotas
(akaquota
) -
serviceaccounts
(akasa
) -
services
(akasvc
)
3.2 Deleting Resources
Problem
You no longer need resources and want to get rid of them.
Solution
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.