kubectl Commands Reference
54 commands with practical examples and interview context.
Update annotations on a resource. Annotations store non-identifying metadata for tools, libraries, and operational information.
Filter API resources by scope — namespaced or cluster-wide. Essential for understanding resource boundaries and RBAC planning.
Print the supported API resources on the server, including their short names, API group, and whether they are namespaced.
Print the supported API versions on the server in the form group/version. Useful for checking API availability and migration planning.
Apply a configuration to a resource by file, stdin, or URL. Creates the resource if it does not exist, updates it if it does.
Attach to a process running inside an existing container. Similar to docker attach, it connects to the main process's stdin/stdout/stderr.
Check whether an action is allowed by the current user or a specified user. Essential for RBAC debugging and verification.
Automatically scale the number of pods in a deployment, ReplicaSet, or StatefulSet based on observed CPU utilization or other metrics.
Approve a CertificateSigningRequest (CSR). Used when manually managing TLS certificates for nodes, users, or webhooks.
Display addresses of the control plane and cluster services. A quick health-check entry point for any Kubernetes cluster.
Generate autocompletion scripts for bash, zsh, fish, or PowerShell. Dramatically improves kubectl productivity.
Display the name of the current context from the kubeconfig. A quick check to confirm which cluster you are targeting.
Display all contexts defined in the kubeconfig, showing the current context, cluster, user, and namespace for each.
Set a context entry in the kubeconfig file, or modify an existing one. Used to bind a cluster, user, and namespace together.
Set the current context in the kubeconfig file. This determines which cluster and user kubectl communicates with.
Display merged kubeconfig settings or a specified kubeconfig file. Essential for understanding cluster access configuration.
Mark a node as unschedulable, preventing new pods from being scheduled onto it. Existing pods continue running.
Copy files and directories to and from containers in pods. Uses tar internally to transfer data.
Create a resource from a file or stdin. Supports imperative creation of many resource types.
Create debugging sessions for troubleshooting workloads and nodes. Supports ephemeral containers, pod copies, and node debugging.
Delete resources by filenames, stdin, resource type and name, or by label selector.
Show detailed information about a specific resource or group of resources, including events.
Diff the live cluster state against the configuration that would be applied. A dry-run comparison tool for safe deployments.
Drain a node by evicting all pods gracefully. The node is cordoned first, then pods are evicted respecting PodDisruptionBudgets.
Edit a resource directly in your default editor. The resource is updated when you save and close the editor.
Display events in the cluster. Events provide a timeline of what happened to resources — scheduling, pulling images, errors, and more.
Execute a command in a container. Provides interactive shell access for debugging running containers.
Get documentation for resource types and their fields directly from the API server schema.
Expose a resource as a new Kubernetes Service. Supports pods, deployments, replica sets, and replication controllers.
Reference for field selectors that filter resources by their spec and status fields, complementing label selectors for precise queries.
Display one or many resources. The most frequently used kubectl command for inspecting cluster state.
Build a set of KRM resources from a kustomization directory. Renders overlays and patches without a separate tool installation.
Reference for label selector syntax used to filter resources across kubectl commands. Covers equality-based and set-based selectors.
Update the labels on a resource. Labels are key-value pairs used for organizing, selecting, and managing Kubernetes resources.
Print the logs for a container in a pod. Supports streaming, multi-container pods, and previous container instances.
Reference for all kubectl output formats including json, yaml, wide, jsonpath, custom-columns, and go-template.
Update fields of a resource using strategic merge patch, JSON merge patch, or JSON patch.
Forward one or more local ports to a pod or service. Creates a tunnel for accessing cluster resources from your local machine.
Run a proxy to the Kubernetes API server on localhost. Handles authentication and allows direct access to the REST API.
Replace a resource by filename or stdin. The resource must already exist, and the entire object is replaced with the new definition.
View the rollout history of a resource, including revision numbers and change causes.
Pause the rollout of a resource. Prevents new ReplicaSets from being created while you make multiple changes to the pod template.
Trigger a rolling restart of a deployment, DaemonSet, or StatefulSet without changing the pod template.
Resume a paused rollout for a deployment, DaemonSet, or StatefulSet. Triggers the rollout of any pending changes.
Show the status of a rollout. Watches the deployment progress and reports whether it completed successfully.
Roll back to a previous revision of a deployment, DaemonSet, or StatefulSet.
Create and run a particular image in a pod. Useful for quick testing and debugging in the cluster.
Set a new size for a deployment, ReplicaSet, or StatefulSet by updating the replica count.
Set specific features on objects. Provides subcommands to update images, environment variables, resources, selectors, service accounts, and subjects.
Update the taints on one or more nodes. Taints work with tolerations to control which pods can be scheduled on specific nodes.
Display resource usage (CPU/memory) for pods and nodes. Requires the Metrics Server to be installed in the cluster.
Mark a node as schedulable again, allowing the scheduler to place new pods on it. Used after maintenance or troubleshooting.
Print the client and server version information for the current context. Essential for compatibility checks and troubleshooting.
Wait for a specific condition on one or more resources. Blocks until the condition is met or a timeout is reached.