kubectl Command Builder

Build correct kubectl commands visually without memorizing every flag. Pick the verb, resource type, optional name, namespace or --all-namespaces, label selector, output format, and contextual flags that change based on the verb (e.g. -f follow for logs, --replicas for scale). The command updates live as you change inputs.

How to use the kubectl Command Builder

Select a Verb — the kubectl action to perform. Then choose the Resource type (pods, deployments, services, etc.). Optionally enter a specific resource Name to target one object; leave blank to target all matching resources.

Set the Namespace to scope the command, or check --all-namespaces to search across every namespace (useful for finding a pod by label across a cluster). Use the Label selector field for -l key=value filtering.

The Output format controls what kubectl prints: wide adds extra columns, json/yaml give machine-readable output, and name returns just the resource identifier. Contextual flags appear below based on the selected verb: for logs you get follow (-f) and tail lines; for scale you get --replicas; for rollout you pick a subcommand; for exec you set the command to run. The command updates live — click Copy when ready.

kubectl Verbs and Resource Types

kubectl is the command-line interface to Kubernetes clusters. It communicates with the Kubernetes API server using your local kubeconfig credentials. The command structure is always kubectl [verb] [resource] [name] [flags]. The verb is an API operation: get retrieves current state, describe gives detailed event and status information, apply reconciles a YAML manifest against the cluster, delete removes resources, and exec opens an interactive session or runs a one-shot command inside a container.

Namespaces are Kubernetes's multi-tenancy primitive: most resources (pods, deployments, services) live in a namespace, while others (nodes, persistent volumes, namespaces themselves) are cluster-scoped. The default namespace is called default. Using -n kube-system targets system components; --all-namespaces (or -A) crosses namespace boundaries — invaluable for cluster-wide searches but it bypasses namespace-level RBAC filtering.

Label selectors (-l app=nginx,tier=frontend) let you target a logical group of resources regardless of their names. This is the standard way to work with pods managed by a deployment, since pod names include a random suffix. The -o yaml and -o json formats are essential for extracting values to pipe into kubectl apply or for use in scripts and CI pipelines.

Common use cases

  • Incident response — quickly build kubectl logs -f -n production deployment/api --tail=100 without looking up the exact flags during an outage.
  • Rollout management — construct kubectl rollout undo deployment/frontend -n staging or rollout status commands with confidence.
  • Cluster exploration — combine -l selectors with --all-namespaces to find all pods belonging to an app across a large multi-tenant cluster.
  • Scaling workflows — generate the correct scale --replicas=N command for a specific deployment without mixing up argument order.
  • Onboarding — teach new team members kubectl syntax visually, letting them see how flags compose before they memorize the CLI.
  • Script generation — use the JSON/YAML output mode options to build commands for use in bash scripts and CI pipelines.

Frequently asked questions

When should I use -o yaml vs -o json?

Use yaml when you plan to edit the output and re-apply it (humans find YAML easier to read). Use json when piping into jq for scripted field extraction. Both contain the same data.

What is the difference between kubectl get and kubectl describe?

get returns structured resource state (columns or serialized object). describe adds Events, Conditions, and related resource details in a human-readable narrative — much more useful for debugging pod scheduling failures or crash loops.

Can I run kubectl exec on a specific container in a multi-container pod?

Yes — add -c container-name. This tool includes a container flag in the exec contextual options. If omitted, kubectl uses the first container defined in the pod spec.

Why does my kubectl command need --all-namespaces flag?

By default kubectl scopes to your current namespace context. If you are searching for a resource and it does not appear, it may be in a different namespace. --all-namespaces (or -A) searches the entire cluster.

What is kubectl rollout used for?

kubectl rollout manages the lifecycle of rolling updates. rollout status blocks until a deployment reaches its target replicas. rollout undo reverts to the previous ReplicaSet. rollout history lists revisions.