kubectl is the Kubernetes cli version of a swiss army knife, and can do many things.
While this Book is focused on using kubectl to declaratively manage applications in Kubernetes, it also covers other kubectl functions.
Most kubectl commands typically fall into one of a few categories:
| Type | Used For | Description |
|---|---|---|
| Declarative Resource Management | Deployment and operations (e.g. GitOps) | Declaratively manage Kubernetes workloads using resource configuration |
| Imperative Resource Management | Development Only | Run commands to manage Kubernetes workloads using Command Line arguments and flags |
| Printing Workload State | Debugging | Print information about workloads |
| Interacting with Containers | Debugging | Exec, attach, cp, logs |
| Cluster Management | Cluster operations | Drain and cordon Nodes |
The preferred approach for managing resources is through declarative files called resource configuration used with the kubectl Apply command. This command reads a local (or remote) file structure and modifies cluster state to reflect the declared intent.
Users will need to view workload state.
kubectl supports debugging by providing commands for:
On occasion, users may need to perform operations to the Nodes of cluster. kubectl supports commands to drain workloads from a Node so that it can be decommissioned or debugged.
Users may find using resource configuration overly verbose for development and prefer to work with the cluster imperatively with a shell-like workflow. kubectl offers porcelain commands for generating and modifying resources.