Kubernetes Commands

Everyday kubectl commands for pods, deployments, nodes and clusters. Every item below is clearly marked as a shortcut, command, or syntax reference.

Most Useful Kubernetes Commands

KubernetesCommand

Apply a Manifest File

Type this command
kubectl apply -f ./my-manifest.yaml

Creates or updates resources from a manifest file.

Learn More
KubernetesCommand

List Pods

Type this command
kubectl get pods

Lists all pods in the namespace.

Learn More
KubernetesCommand

Dump Pod Logs

Type this command
kubectl logs my-pod

Dumps a pod's logs to your terminal.

Learn More
KubernetesCommand

Stream Pod Logs

Type this command
kubectl logs -f my-pod

Streams pod logs as they are written.

Learn More
KubernetesCommand

Open a Shell in a Pod

Type this command
kubectl exec --stdin --tty my-pod -- /bin/sh

Opens an interactive shell into a running pod.

Learn More
KubernetesCommand

Switch Cluster Context

Type this command
kubectl config use-context <cluster-name>

Sets the default context to the named cluster.

Learn More
KubernetesCommand

List Pods in All Namespaces

Type this command
kubectl get pods --all-namespaces

Lists all pods in every namespace.

Learn More
KubernetesCommand

Update a Deployment Image

Type this command
kubectl set image deployment/frontend www=image:v2

Performs a rolling update of a container's image.

Learn More

More Kubernetes Commands

Frequently Asked Questions

What are the most useful Kubernetes commands?

Common Kubernetes commands include Apply a Manifest File (kubectl apply -f ./my-manifest.yaml), List Pods (kubectl get pods), Dump Pod Logs (kubectl logs my-pod), Stream Pod Logs (kubectl logs -f my-pod), Open a Shell in a Pod (kubectl exec --stdin --tty my-pod -- /bin/sh).

Where do I type Kubernetes commands?

Type each command in the terminal or command-line interface used by Kubernetes.

What should I check before running a Kubernetes command?

Read its reference page and the linked documentation for prerequisites and placeholders. Check the current directory and target before running commands that change or delete data.