Everyone who works with more than one cluster has a version of this story. You meant to delete a Deployment in staging. kubectl was pointed at production. The command did exactly what you asked, quickly and without complaint, because that's its job.
It's rarely carelessness. It's how kubectl stores state.
Why it happens
kubectl config use-context doesn't change anything about your terminal. It rewrites current-context in your kubeconfig file, usually ~/.kube/config. Every terminal, script and tool that reads that file now points at the new cluster, including the terminal you switched an hour ago and forgot about.
So the context you see in one window isn't necessarily the context you're using in another. Add kubectx muscle memory, a few tabs and a pager going off, and you have the classic setup.
1. Make the context impossible to miss
Put the current context in your shell prompt. kube-ps1 does it for bash and zsh, and Starship has a kubernetes module (off by default) that can color the prompt by context name:
[kubernetes]
disabled = false
contexts = [
{ context_pattern = ".*prod.*", style = "bold red" },
]
A red prompt won't stop a determined finger, but it does make "wait, which cluster?" a reflex.
2. Give each terminal its own context
The real fix for shared state is to stop sharing it. KUBECONFIG can point at a file per shell:
# a private copy for this terminal; use-context here changes nothing elsewhere
cp ~/.kube/config ~/.kube/config.$$
export KUBECONFIG=~/.kube/config.$$
The copies contain your credentials, so clean them up (rm ~/.kube/config.* once those shells are closed), or skip the copying: kubie does this for you: kubie ctx staging opens a shell whose context is staging and stays staging, whatever happens in the next tab.
3. Name contexts so production looks like production
Cloud CLIs generate names like arn:aws:eks:us-east-1:123456789012:cluster/main and gke_acme-prod_us-central1_main. They're unique, and unreadable at 2 a.m. Rename them:
kubectl config rename-context gke_acme-prod_us-central1_main prod-us-central
Then "prod" is in every prompt, every error and every kubectl config get-contexts.
4. Be explicit in anything you'll run twice
Scripts, runbooks and aliases should never rely on current-context:
kubectl --context prod-us-central -n shop rollout restart deploy/checkout
It's longer. It's also the only version of that command that does the same thing every time you run it. An alias such as alias kprod='kubectl --context prod-us-central' keeps it short.
5. Have no default at all
If you'd rather kubectl refuse than guess, remove the default:
kubectl config unset current-context
Now a bare kubectl get pods fails (with a confusing message about localhost:8080, but fails) until you pass --context. It's annoying for about a day, and then it's just how you type.
6. Use read-only credentials for production
Prompts and habits reduce mistakes. Permissions prevent them. If your day-to-day production access is a user or role bound to the built-in view ClusterRole, a wrong-context delete is a Forbidden error instead of an incident. Keep write access in a separate context you switch to on purpose:
kubectl --context prod-us-central auth can-i delete deployments -n shop
# no
This is the one item on the list that also protects you from scripts, tools and coding agents, not just tired humans.
7. Look before you write
kubectl diff shows what an apply would change, computed by the API server, before anything is written:
kubectl --context staging diff -f checkout.yaml
If the diff is enormous, or names objects you don't recognize, you're probably not where you think you are.
Where Klystiq fits
I built Klystiq partly because of this problem, so it's opinionated about it. Every row in every list shows which context it came from, with a color per cluster. Writes go to the cluster the object came from, not to whatever is "current". You can mark a context read-only, and Klystiq then refuses every write to it in its backend, not just by hiding buttons. And every change gets a server-side dry run and a diff first. It doesn't touch your kubeconfig, so everything above still works alongside it.
But do the read-only credentials either way. They're the fix that works for every tool, including the ones you haven't installed yet.