A quick reference for Kubernetes with the most important commands and options. Read it online below, or download the printable PDF.
Download PDF| Resource | Description |
|---|---|
pods (po) |
One or more containers on the same node and IP |
deployments (deploy) |
Manages a set of identical, stateless pods |
replicasets (rs) |
Keeps a set of pods running; made by a deployment |
statefulsets (sts) |
Pods with stable names and their own storage |
daemonsets (ds) |
Runs one pod on every node |
jobs |
Runs pods until they complete successfully |
cronjobs (cj) |
Creates jobs on a schedule |
horizontalpodautoscalers (hpa) |
Scales pods based on CPU or custom metrics |
services (svc) |
Stable network address and load balancing for pods |
ingresses (ing) |
Routes external HTTP traffic to services |
networkpolicies (netpol) |
Firewall rules for pod traffic; needs CNI support |
| Resource | Description |
|---|---|
configmaps (cm) |
Non-confidential config, as files or env vars |
secrets |
Confidential data; base64-encoded, not encrypted |
persistentvolumeclaims (pvc) |
A request for storage by a pod |
persistentvolumes (pv) |
A volume provisioned for a claim |
storageclasses (sc) |
Defines how volumes are provisioned |
nodes (no) |
A worker machine that runs pods |
namespaces (ns) |
Groups and isolates resources |
| Flag | Description |
|---|---|
--kubeconfig <file> |
Use a non-default kubeconfig file |
--context <context> |
The name of the context to use |
-n, --namespace <namespace> |
The name of the namespace to use |
-A, --all-namespaces |
Operate on every namespace |
--help |
Show information about a given command |
| Command | Description |
|---|---|
kubectl get <resource> |
List all resources of this type in current namespace |
kubectl get <resource> -o wide |
List all resources with more details |
kubectl get <resource> <name> |
Show a particular resource |
kubectl get <resource> <name> -o yaml |
Print a particular resource in YAML format |
kubectl get <resource> -l <key>=<value> |
List resources where label <key> equals <value> |
kubectl describe <resource> <name> |
Show detailed information about a resource |
kubectl api-resources |
Print the supported API resources on the server |
| Command | Description |
|---|---|
kubectl logs <pod> |
Print the logs for a pod |
kubectl logs -f <pod> |
Print the logs for a pod and keep streaming |
kubectl logs -p <pod> |
Print logs for the previous container instance |
kubectl events |
Show recent events in the namespace |
kubectl events --for <resource>/<name> |
Show the events for one object |
kubectl top <node|pod> |
Usage per node or per pod; needs metrics-server |
kubectl exec <pod> -- <command> |
Execute a command in a running pod |
kubectl exec -it <pod> -- bash |
Open bash in a running pod |
| Status | Meaning |
|---|---|
Pending |
Not scheduled; no node fits, or a PVC is unbound |
ContainerCreating |
Pulling the image and mounting volumes |
ImagePullBackOff |
Image not found, or the registry needs credentials |
CrashLoopBackOff |
The container keeps exiting; check logs -p |
CreateContainerConfigError |
A referenced configmap or secret is missing |
OOMKilled |
The container exceeded its memory limit |
Evicted |
The node ran out of resources and removed the pod |
Completed |
All containers exited successfully |
| Command | Description |
|---|---|
kubectl apply -f <file|directory> |
Apply manifests from a file or directory |
kubectl diff -f <file> |
Show what applying the file would change |
kubectl apply -k <directory> |
Apply resources from a kustomize directory |
kubectl delete -f <file|directory> |
Delete the resources defined in the manifests |
| Command | Description |
|---|---|
kubectl run <name> --image=<image> |
Manually create a pod |
kubectl create deploy <name> --image=<image> |
Create a deployment |
kubectl expose <resource> <name> --port=<port> |
Create a service for a pod / deployment / etc. |
kubectl create secret generic <name> --from-literal=<key>=<value> |
Create a secret containing <key> and <value> |
kubectl ... --dry-run=client -o yaml |
Print the YAML manifest instead of creating it |
kubectl edit <resource> <name> |
Edit a resource in a text editor |
kubectl set image <resource> <name> <container>=<image> |
Update container image(s) of a workload |
kubectl <label|annotate> <resource> <name> <key>=<value> |
Add a label or annotation to a resource |
kubectl delete <resource> <name> |
Delete a particular resource |
kubectl delete <resource> --all |
Delete all resources of this type in the namespace |
| Command | Description |
|---|---|
kubectl rollout status deployment <name> |
Show the status of a deployment rollout |
kubectl rollout history deployment <name> |
View the rollout history of a deployment |
kubectl rollout undo deployment <name> |
Roll back to the previous revision |
kubectl rollout restart deployment <name> |
Restart a deployment |
kubectl scale deployment <name> --replicas=<n> |
Scale a deployment to <n> replicas |
| Field | Effect |
|---|---|
livenessProbe |
Restarts the container when it fails |
readinessProbe |
Takes the pod out of the service's endpoints |
startupProbe |
Delays the other probes until the app has started |
resources.requests |
CPU/memory reserved; used to pick a node |
resources.limits |
Ceiling; CPU throttles, memory gets OOMKilled |
cpu: 500m, memory: 1Gi |
Millicores and binary units |
| Type | Description |
|---|---|
ClusterIP |
Default; reachable inside the cluster only |
NodePort |
On a fixed port of every node |
LoadBalancer |
Via a cloud load balancer; adds a NodePort |
| Resource | Description |
|---|---|
roles |
Permissions to act on resources in a namespace |
clusterroles |
The same, not limited to one namespace |
rolebindings |
Grants a role to a user or service account |
clusterrolebindings |
Grants a cluster role in all namespaces |
serviceaccounts (sa) |
Identity for pods which talk to the API server |
| Command | Description |
|---|---|
kubectl config get-contexts |
List all contexts |
kubectl config current-context |
Display the current context |
kubectl config use-context <context> |
Switch to another context |
kubectl auth whoami |
Display your username and groups |
kubectl auth can-i --list |
List all allowed actions in the current namespace |
Follow the instructions at https://kubernetes.io/docs/tasks/tools/#kubectl to install kubectl.