kubectl commands
To get a list of supported kubectl
commands, run this:
$ kubectl --help
kubectl
commands are grouped by category. Let's look at each category.
Basic commands
The following are basic kubectl
commands:
create
: Create a resource from a file or fromstdin
; for example, create a Kubernetes deployment from the file.expose
: Take a service, deployment, or pod and expose it as a new Kubernetes Service.run
: Run a particular image on the cluster.set
: Set specific features on objects—for example, set environment variables, update a Docker image in a pod template, and so on.explain
: Get the documentation of resources—for example, the documentation on deployments.get
: Display one or many resources. For example, you can get a list of running pods or the YAML output of a pod.edit
: Edit a resource—for example, edit a deployment.delete
: Delete resources by filenames,stdin
, resources, and names, or by resources and label selectors.
Deploy commands
The following are kubectl
deploy commands:
rollout
: Manage the rollout of a resource.scale
: Set a new size for a deployment, ReplicaSet, or StatefulSet.autoscale
: Auto-scale a deployment, ReplicaSet, or StatefulSet.
Cluster management commands
The following are the kubectl
cluster management commands:
certificate
: Modify certificate resources.cluster-info
: Display cluster information.top
: Display resource (CPU/memory/storage) usage.cordon
: Mark a node as unschedulable.uncordon
: Mark a node as schedulable.drain
: Drain a node in preparation for maintenance.taint
: Update the taints on one or more nodes.
Troubleshooting and debugging commands
The following are the kubectl
troubleshooting and debugging commands:
describe
: Show the details of a specific resource or group of resources.logs
: Print the logs for a container in a pod.attach
: Attach to a running container.exec
: Execute a command in a container.port-forward
: Forward one or more local ports to a pod.proxy
: Run a proxy to the Kubernetes API server.cp
: Copy files and directories to and from containers.auth
: Inspect authorization.
Advanced commands
The following are the kubectl
advanced commands:
diff
: Show difference of live version against a would-be applied version.apply
: Apply a configuration to a resource by filename orstdin
.patch
: Update the field(s) of a resource using a strategic merge patch.replace
: Replace a resource by filename orstdin
.wait
: Wait for a specific condition on one or many resources.convert
: Convert config files between different API versions.kustomize
: Build a kustomization target from a directory or a remote URL.
Settings commands
The following are the settings commands in kubectl
:
label
: Update the labels on a resource.annotate
: Update the annotations on a resource.
Other commands
The following are several other commands used in kubectl
:
alpha
: Commands for features in alpha.api-resources
: Print the supported API resources on the server.api-versions
: Print the supported API versions on the server, in the form of group/version.config
: Modifykube-config
files.plugin
: Provide utilities for interacting with plugins.version
: Print the client and server version information.
As you can see from the lists, commands are divided into different groups. We are going to learn about most but not all of these commands in the coming chapters.
At the time of writing, the kubectl
version is 1.18; with more recent versions, the commands might have changed.