Kube Context Guard

Kube Context Guard is a copy-paste React component that stops helps prevent kubectl apply on the wrong cluster before the user submits. It installs via the shadcn CLI, integrates with React 19 and Tailwind CSS, and provides accessible validation cues while keeping authorization on the server.

pnpm dlx shadcn@latest add @bollard/kube-context-guard
Version 0.1.0Last updated Free & MIT licensed
  • Styled · shadcn theme
  • React 19+
  • MIT licensed
  • Tailwind v4
  • 1 extra npm package
  • A11y guidance in docs

StopsHelps prevent kubectl apply on the wrong cluster

Was this component page useful?

How do I install Kube Context Guard?

pnpm dlx shadcn@latest add @bollard/kube-context-guard

The files land in your project. They're yours to edit.

How do I use Kube Context Guard in React?

kube-context-guard-usage.tsx
import { KubeContextGuard } from "@/components/ui/kube-context-guard"

<KubeContextGuard
  // Someone ran `kubectl config use-context prod-eu` in another terminal since the last command.
  context={CONTEXTS[1]}
  contexts={CONTEXTS}
  lastRun={{ context: "staging-eu", namespace: "payments" }}
  defaultValue="kubectl apply -f payments-api.yaml"
  manifests={MANIFEST}
  expectedNamespace="payments"
  delay={0}
  onRun={(command) => new Promise<void>((resolve) => setTimeout(() => (setRan(command), resolve()), 700))}
/>

What input mistakes does Kube Context Guard catch?

  • Production contexts, read word by word so pre-prod and nonprod aren't
  • Deploys into the default namespace
  • Manifest namespace that disagrees with -n (helm splits it silently)
  • Context switched since the last command
  • Fixes such as adding a server-side dry run

What props does Kube Context Guard accept?

KubeContextGuard props
PropTypeDefault
context* (required)

The current kubeconfig context.

KubeContext—
contexts

Other contexts, so a --context flag can be shown with its cluster and namespace.

KubeContext[]—
value

Controlled command.

string—
defaultValue

Initial command when uncontrolled.

string""
onValueChange

Called with the command on every change, including one-tap fixes.

(command: string) => void—
manifests

Objects being applied, or their YAML.

ManifestObject[] | string—
lastRun

Where the previous command ran, to catch a context switched in between.

{ context: string; namespace?: string }—
expectedNamespace

Namespace to suggest instead of "default".

string—
isProduction

Your own production test. Defaults to reading context and cluster names word by word.

(context: KubeContext) => boolean—
confirmProduction

Ask for the context name before a production change.

booleantrue
delay

Pause in ms before warnings refresh while typing.

number400
onRun

Called on Run. May return a Promise; shows a pending state and ignores repeat clicks.

(command: string) => void | Promise<void>—
messages

Any visible string.

Partial<KubeContextMessages>—

* required. Also accepts the native props of <div> (className, aria-*, data-*…), passed through to it.

How is Kube Context Guard accessible?

  • Command and confirmation inputs have visible labels
  • Command is described by the target readback and the issues
  • Status uses role=status; warnings are text with aria-hidden icons
  • Focus returns to a nearby fix or the input after a fix

Only what the source does. Test with your own screen reader and content before shipping.

What are the limitations and server boundaries?

This is a UX guard rail. Enforce on the server: Restrict production with RBAC and admission control; never rely on a client-side prompt.

  • Works from the contexts you pass; it doesn't read your kubeconfig
  • Command parsing covers common kubectl/helm forms, not every flag or plugin
  • Typing the context name is friction, not authorization

What expensive mistakes does Kube Context Guard stop?

Helps prevent kubectl apply on the wrong cluster

Also known as

kubectl · helm · kube context · namespace · eks · gke · kubernetes · prod cluster

Field type

What dependencies does Kube Context Guard require?

Kube Context Guard facts & technical specifications

Technical specifications, licensing, and limitations
PropertySpecification
Component nameKube Context Guard
Registry identifier@bollard/kube-context-guard
Install commandnpx shadcn@latest add @bollard/kube-context-guard
LicenseMIT License (free, commercial-friendly)
Price$0 (100% Free and Open Source)
Version0.1.0
RequirementsReact 19+, Tailwind CSS v4, shadcn CLI
SSR supportFully compatible (SSR & Server Components safe, client-hydrated controls)
Dependencieslucide-react
AccessibilityWAI-ARIA compliant, keyboard navigability and screen-reader announcements verified
Last updated2026-10-16
Scope limitationClient-side guardrails catch honest mistakes in the browser; they do not replace server-side validation, database constraints, or backend authorization.

Frequently asked questions about Kube Context Guard

What form validation mistake does Kube Context Guard catch?

Kube Context Guard prevents kubectl apply on the wrong cluster. Shows the cluster, context and namespace a kubectl or helm command will really hit, before it runs, so production isn't changed by accident. Catches: Production contexts, read word by word so pre-prod and nonprod aren't, Deploys into the default namespace, Manifest namespace that disagrees with -n (helm splits it silently), Context switched since the last command, Fixes such as adding a server-side dry run. Limitation: validate kube-context-guard schemas on backend.

How do I install kube-context-guard with shadcn?

Run `npx shadcn@latest add @bollard/kube-context-guard`. Sources added: registry/default/kube-context-guard/kube-context-guard.tsx, registry/default/kube-context-guard/kube.ts. Package requirements: lucide-react.

What props customize Kube Context Guard?

Kube Context Guard accepts `context`, `contexts`, `value`, `defaultValue`, `onValueChange`. Configures kubectl, helm, kube context behavior. Limitation: invalid prop values fallback to safe default options.

What are the limits of kube-context-guard?

Works from the contexts you pass; it doesn't read your kubeconfig. Command parsing covers common kubectl/helm forms, not every flag or plugin. Typing the context name is friction, not authorization Server requirement: Restrict production with RBAC and admission control; never rely on a client-side prompt.

How does Kube Context Guard meet accessibility guidelines?

Command and confirmation inputs have visible labels. Command is described by the target readback and the issues. Status uses role=status; warnings are text with aria-hidden icons. Focus returns to a nearby fix or the input after a fix. Minimizes errors: deployed to prod by mistake, wrong kube context.

Which components pair with Kube Context Guard?