D

Kubernetes

kubectl commands for cluster inspection, workloads, debugging and rollouts.

Updated 2026-09-03

On this page

kubectl is the control surface for everything in a cluster. This page groups commands the way you'll actually reach for them — inspecting state, shipping a change, and digging into a failure.

Cluster Information

kubectl cluster-info

Shows the control plane and core service endpoints for the current context.

kubectl config current-context

Prints which cluster/user/namespace kubectl is currently pointed at.

kubectl config get-contexts

Lists every cluster context available in your kubeconfig.

kubectl config use-context CONTEXT_NAME

Switches the active context — the cluster every subsequent command targets.

Nodes

kubectl get nodes

Lists cluster nodes and their Ready status.

kubectl get nodes -o wide

Adds internal/external IP, OS image and container runtime per node.

kubectl describe node NODE_NAME

Shows capacity, allocatable resources, conditions and the pods scheduled on a node.

kubectl top node

Shows live CPU/memory usage per node. Requires the metrics-server add-on.

Pods

kubectl get pods

Lists pods in the current namespace.

kubectl get pods -A

Lists pods across every namespace.

kubectl get pods -o wide

Adds pod IP and the node it's scheduled on.

kubectl get pods --watch

Streams pod status changes live instead of a single snapshot.

kubectl describe pod POD_NAME

Shows full pod detail: containers, events, volumes, conditions — usually the first move when a pod misbehaves.

kubectl delete pod POD_NAME
destructive

Deletes the pod. If it's managed by a Deployment or ReplicaSet, a replacement is scheduled immediately — often the fastest way to force a clean restart.

Deployments

kubectl get deployments

Lists deployments and their desired/current/up-to-date/available replica counts.

kubectl describe deployment DEPLOYMENT_NAME

Shows rollout strategy, replica status and recent events for a deployment.

kubectl scale deployment DEPLOYMENT_NAME --replicas=5

Changes the desired replica count directly.

kubectl set image deployment/DEPLOYMENT_NAME CONTAINER_NAME=IMAGE:TAG

Updates a deployment's container image, triggering a rolling update.

Services & Ingress

kubectl get svc

Lists services and their type, cluster IP and exposed ports.

kubectl describe svc SERVICE_NAME

Shows the service's selector and its resolved endpoints — the fastest way to confirm it's actually matching any pods.

kubectl get endpoints SERVICE_NAME

Lists the pod IPs a service currently routes to. Empty output means the selector isn't matching any ready pod.

kubectl get ingress

Lists ingress resources and the hosts/paths they route.

kubectl describe ingress INGRESS_NAME

Shows backend resolution and recent events for an ingress — useful when a host routes but 404s or 502s.

ConfigMaps & Secrets

kubectl get configmaps

Lists ConfigMaps in the current namespace.

kubectl create configmap my-config --from-file=config.yaml

Creates a ConfigMap from a local file.

kubectl get secrets

Lists Secrets in the current namespace (values are not shown).

kubectl get secret SECRET_NAME -o jsonpath='{.data.password}' | base64 -d

Decodes a single key from a Secret. Secret data is base64-encoded, not encrypted at this layer.

Logs

kubectl logs POD_NAME

Prints a pod's current container logs.

kubectl logs -f POD_NAME

Streams logs live as they're written.

kubectl logs POD_NAME --previous

Shows logs from the container's previous run — essential after a crash, since the current container has no history yet.

kubectl logs POD_NAME -c CONTAINER_NAME

Targets one container in a multi-container pod.

Exec & Debugging

kubectl exec -it POD_NAME -- /bin/bash

Opens an interactive shell inside a running container.

kubectl exec POD_NAME -- env

Runs a single command inside the container without an interactive shell.

kubectl debug POD_NAME -it --image=busybox

Attaches an ephemeral debug container to a running pod — useful when the pod's own image has no shell.

kubectl port-forward pod/POD_NAME 8080:80

Forwards a local port to a port on the pod, for reaching a service directly without going through its Service object.

Resource Usage

kubectl top pods

Shows live CPU/memory usage per pod in the current namespace. Requires metrics-server.

kubectl top pods --containers

Breaks usage down per container instead of summing per pod.

Rollouts

kubectl rollout status deployment/DEPLOYMENT_NAME

Watches a rollout until it completes or stalls.

kubectl rollout history deployment/DEPLOYMENT_NAME

Lists revisions for a deployment.

kubectl rollout undo deployment/DEPLOYMENT_NAME
destructive

Rolls back to the previous revision immediately.

kubectl rollout restart deployment/DEPLOYMENT_NAME

Restarts every pod in a deployment with a fresh rolling update, without changing the image or config.

Labels & Namespaces

kubectl get pods -l app=web

Filters pods by label selector.

kubectl label pod POD_NAME env=staging

Adds or updates a label on a resource.

kubectl get namespaces

Lists all namespaces in the cluster.

kubectl config set-context --current --namespace=my-namespace

Sets the default namespace for the current context, so you stop typing -n on every command.

RBAC

kubectl get roles,rolebindings -n NAMESPACE

Lists namespace-scoped roles and their bindings.

kubectl get clusterroles,clusterrolebindings

Lists cluster-wide roles and their bindings.

kubectl auth can-i delete pods --as=system:serviceaccount:default:my-sa

Checks whether a given identity is permitted an action — the fastest way to debug a Forbidden error.

Storage

kubectl get pv,pvc

Lists PersistentVolumes and PersistentVolumeClaims and their Bound/Pending status.

kubectl describe pvc PVC_NAME

Shows why a claim is still Pending — usually no matching StorageClass or provisioner, or insufficient capacity.

Helm

Helm packages and versions Kubernetes manifests as charts. See the dedicated Helm cheat sheet for install, upgrade and rollback commands.

Debugging

kubectl get events --sort-by=.lastTimestamp

Lists cluster events newest-last — scheduling failures, image pull errors and probe failures all show up here before they show up in logs.

kubectl get all -n NAMESPACE

Lists every common resource type in a namespace in one shot — a fast first look at what's actually running.

See the Kubernetes Troubleshooting tab for CrashLoopBackOff, ImagePullBackOff, stuck Pending pods, probe failures and more, each with a step-by-step diagnostic sequence.

Official documentation