DevTools Logo

Kubectl Command Builder

Kubectl Command Builder

Compose correct, safely quoted kubectl commands with scoped flag chips. Nothing connects to a cluster.

Runs in your browser

Builder only — commands are never executed and no cluster is contacted.

Try an example
Inspect
Operate
Debug
Config

Command inputs

Flags for get

Command preview

16 chars
kubectl get pods

Alias: kgp · Flags use canonical boolean-then-value order.

Recipes

Examples

Previous container logs

Input
logs · web-7d9f · -c app · --previous · --tail=200 · -n prod
Output
kubectl logs web-7d9f --previous -c app --tail=200 -n prod

The classic CrashLoopBackOff command, built without memorising flag combinations.

Interactive shell

Input
exec · api-0 · -it · /bin/sh
Output
kubectl exec api-0 -i -t -- /bin/sh

The remote command always follows -- and each token is safely quoted.

Invalid port pair

Input
port-forward · pod/api · http
Output
Error: "http" is not a local:remote port pair (use :80 for a random local port).

Constraints are enforced before a command can be copied.

About this tool

Kubectl Command Builder turns the kubectl flags you half-remember into a form. Choose from sixteen command families — get, describe, logs, exec, port-forward, cp, rollout, scale, apply, delete, top, auth can-i, config, explain, edit and patch — and the flag chips change to the ones that family actually accepts.

The composer assembles a canonical line: verb, positional arguments, boolean flags, valued flags, then namespace and context. Values containing spaces or shell metacharacters are single-quoted with embedded quotes escaped, so a pod name or patch body pasted from a ticket cannot turn into a shell injection when you paste the command into a terminal.

It is a builder, not a client: no kubeconfig is read, no API call is made and nothing is executed. Recipes generate three-command debug sequences, and the history lets you restore a composed command. Your names, namespaces and context stay in the tab.

What this tool does not do

  • The schema covers the listed families and their common flags; new kubectl versions may add flags not yet in the chips.
  • Custom extra flags are appended verbatim after validation of plain --flag or --flag=value shape.
  • POSIX single-quoting is used; PowerShell needs different escaping and receives a note for Windows paths.
  • History and recipes live in memory for the current visit only; nothing is persisted to disk.
  • No command is ever executed; copy the preview and run it in a terminal you control.

How to use this tool

  1. Choose a family

    Pick a verb from the Inspect, Operate, Debug or Config rail. The flag chips are scoped to that verb — --previous only appears for logs.

  2. Fill the inputs

    Enter resource and name, namespace and context. rollout and patch expect type/name targets; cp expects source and destination paths.

  3. Toggle flags

    Use checkboxes for booleans and inline inputs for valued flags such as --tail, -c and -o. The preview updates on every change.

  4. Handle the constraints

    Conflicts are resolved with a note (-A drops -n); missing requirements become errors with a plain-language fix.

  5. Copy or save

    Copy the command, copy a whole recipe, or save it to history for later. Nothing runs automatically.

Use cases

Incident triage

Load the debug-crashloop recipe to get describe and previous-container logs with one click.

On-call handoff

Copy a correctly namespaced, quoted command into a ticket instead of a vague description.

Learning kubectl

See which flags belong to which verb and what happens when incompatible flags are combined.

Multi-cluster work

Keep context and namespace in the preview so a pasted command targets the right cluster.

Command shape

PartRule
verbkubectl plus the family verb; auth and rollout include their subcommand
argumentsResource/name, pod name, port pairs or paths, quoted when unsafe
boolean flags--follow, --previous, -A, -i -t and friends, in declaration order
valued flags-c app, --tail=200, -l 'app=web', -o wide, then -n and --context
exec terminatorRemote command follows -- and is quoted token by token

Values are single-quoted when they contain whitespace or shell metacharacters; an embedded quote becomes '\''.

Common mistakes

Mistake:Using -A and -n together.

Fix:kubectl rejects the combination; the builder keeps -A and shows a note that -n was dropped.

Mistake:Forgetting the -- before an exec command.

Fix:The builder inserts -- and quotes the remote command tokens for you.

Mistake:Assuming a rollout target is just a name.

Fix:Use deployment/name; the builder flags targets with zero or more than one slash.

Mistake:Pasting a patch body with quotes or shell metacharacters.

Fix:Valued arguments are single-quoted, with internal quotes escaped, before they reach the preview.

Mistake:Expecting the tool to run the command.

Fix:It only builds text. Nothing is executed and no cluster is contacted.

Frequently asked questions

How do I see the previous container's logs?

Choose the logs family, enter the pod name, tick --previous and optionally set -c and --tail. The builder emits kubectl logs <pod> --previous -c <container> --tail=200 -n <namespace>. The previous container is the one that ran before the current one in the same pod — useful for CrashLoopBackOff.

What's the difference between exec -it and attach?

attach connects to the main process of an existing container; exec starts a new process inside it. Tick the -it chip to allocate a TTY and keep stdin open, then type the remote command after --, for example /bin/sh. The builder never attaches; it only composes the exec line.

How do I target all namespaces?

Tick --all-namespaces (or use -A). Since kubectl treats -A and -n as mutually exclusive, the builder drops any namespace you entered and shows a note in the warnings strip instead of producing an invalid command.

How are names with special characters quoted?

Any value containing whitespace or a shell metacharacter is wrapped in single quotes, and embedded single quotes become '\''. A pod name with a space or a JSON patch body therefore stays one argv element when you paste the command into a POSIX shell. Non-ASCII characters are preserved byte-for-byte.

Can it run commands for me?

No. The builder never reads your kubeconfig, opens a socket or executes anything. It only assembles text in your tab, which you can copy and run in a terminal you control. Recipes and history are conveniences for composing and restoring text.

Why does port-forward validate my port pairs?

kubectl accepts local:remote pairs, an empty local port such as :80 for a randomly assigned one, and several pairs separated by spaces. Anything else is reported before you copy. Ports outside 1–65535 are rejected as well.

References & standards