Reference · 18 entries
kubectl Reference
The kubectl commands you use every day: get, describe, apply, rollout, logs, exec, debug, events, port-forward and auth can-i, with options and real examples run against Kubernetes 1.37.
kubectl 1.37 Version history
Every example was run against a real Kubernetes 1.37 cluster when this page was built, so the output is real. Each example creates its own namespace and deletes it at the end. For explanations of the concepts, see the Kubernetes tutorial.
Basics
Read, create, update and delete resources with kubectl get, describe, apply, delete, create and explain.
| Name | Description |
|---|---|
kubectl get | List resources in a table, or print them as YAML, JSON, JSONPath or custom columns for scripts and debugging. |
kubectl describe | Show a detailed, human-readable view of a resource, including related events, the first place to look when debugging. |
kubectl apply | Create or update resources from files, directories or Kustomize folders declaratively; the standard way to deploy manifests. |
kubectl delete | Delete resources by name, file or label selector; deleting a namespace deletes everything inside it. |
kubectl create | Create resources imperatively from the command line: namespaces, deployments, configmaps, secrets, jobs and more. |
kubectl explain | Show documentation for any resource field straight from the cluster's API schema, including nested fields. |
Workloads
Roll out, roll back, scale and relabel workloads with kubectl rollout, scale, set image and label.
| Name | Description |
|---|---|
kubectl rollout | Manage Deployment, StatefulSet and DaemonSet rollouts: watch status, view history, restart and undo to a previous revision. |
kubectl scale | Set the number of replicas of a Deployment, ReplicaSet or StatefulSet; avoid it for workloads managed by an autoscaler. |
kubectl set image | Change the image of one or more containers in a workload's pod template, which starts a rolling update. |
kubectl label | Add, change or remove labels on resources; labels drive selectors for Services, Deployments, network policies and queries. |
Debugging
Find out what's wrong with kubectl logs, exec, port-forward, events and debug.
| Name | Description |
|---|---|
kubectl logs | Print a container's logs from a pod, deployment or job; follow them, limit lines, or read the previous crashed container. |
kubectl exec | Run a command in a container of a running pod, for example a shell, a database client or a quick check. |
kubectl port-forward | Forward a local port to a pod or Service for testing and debugging without exposing it publicly. |
kubectl events | List recent cluster events (scheduling, image pulls, probe failures, kills) for a namespace or one resource, sorted by time. |
kubectl debug | Debug pods and nodes with ephemeral containers or copies, even when the image has no shell or tools. |
Access and Configuration
Check permissions, preview changes and switch clusters with kubectl auth can-i, diff and config.
| Name | Description |
|---|---|
kubectl auth can-i | Check whether you, or another user or service account via --as, may perform an action; --list shows everything allowed. |
kubectl diff | Show what kubectl apply would change in the cluster, as a diff against the live objects, before you apply it. |
kubectl config | Inspect and switch kubeconfig contexts (cluster, user and default namespace), and set the namespace for the current context. |