Code & computing / QUICK REFERENCE

kubectl inspection

Contexts, resources, logs and safe diagnostics for finding your way around a Kubernetes cluster.

32 entries

Confirm context and permissions

Client version
kubectl version --client

Does not need a live API server. [2][1]

Current context
kubectl config current-context

Check this before any cluster operation. [2][1]

List contexts
kubectl config get-contexts

Shows configured cluster/user/namespace combinations. [2][1]

Inspect active config
kubectl config view --minify

Displays the current context subset with normal redaction. [2][1]

Choose context for one command
kubectl --context dev get namespaces

Avoids changing the saved default context. [2][1]

Choose namespace for one command
kubectl -n tools get pods

Limits this request to the specified namespace. [2][1]

Check a permission
kubectl auth can-i get pods -n tools

Asks the server about your effective access. [2][1]

Discover API resource types
kubectl api-resources

Lists resource names exposed by the cluster. [2][1]

Read resources

List namespaces
kubectl get namespaces

Lists namespace resources. [3][1]

List nodes
kubectl get nodes

Requires cluster-scope permission. [3][1]

Pods in current namespace
kubectl get pods

Does not include other namespaces by default. [3][1]

Pods across namespaces
kubectl get pods -A

Requires access to the requested resources. [3][1]

Expanded pod columns
kubectl get pods -o wide

Includes placement and IP information. [3][1]

Filter by label
kubectl get pods -l app=web

Selects pods carrying that label. [3][1]

Watch updates
kubectl get pods -w

Streams changes until interrupted. [3][1]

Describe one pod
kubectl describe pod pod-name

Summarizes configuration, conditions and recent events. [3][1]

Workloads and discovery

Deployments
kubectl get deployments

Lists deployment resources in scope. [1]

Services
kubectl get services

Shows service types and ports. [1]

Ingress rules
kubectl get ingress

Lists ingress resources, not proof of external reachability. [1]

Stateful workloads
kubectl get statefulsets

Inspects stateful application controllers. [1]

Daemon workloads
kubectl get daemonsets

Lists per-node workload controllers. [1]

Batch jobs
kubectl get jobs

Shows job resources and completion counts. [1]

Explain a field
kubectl explain deployment.spec.replicas

Uses the server-published resource schema. [1]

View resource JSON
kubectl get deployment web -o json

Includes configuration; redact before sharing. [1]

Logs, events and rollout status

Pod logs
kubectl logs pod-name

May require -c when several containers are present. [4][1]

One container's logs
kubectl logs pod-name -c app

Selects a container by name. [4][1]

Recent log lines
kubectl logs pod-name --tail=100

Limits returned lines. [4][1]

Follow logs
kubectl logs -f pod-name

Ctrl+c ends the stream. [4][1]

Previous container logs
kubectl logs pod-name --previous

Available only when the prior instance's logs remain. [4][1]

Recent events
kubectl get events --sort-by=.metadata.creationTimestamp

Events are transient diagnostic records. [4][1]

Rollout progress
kubectl rollout status deployment/web --timeout=60s

Waits for status without initiating a new rollout. [4][1]

Resource usage
kubectl top pods

Requires a functioning metrics API; missing metrics do not mean zero usage. [4][1]

Reserved placement, separate from reference controls. No ad network is active.

Updated kubectl · common inspection commands

Sources

  1. kubectl quick reference ↗
  2. kubectl config reference ↗
  3. kubectl get reference ↗
  4. kubectl logs reference ↗