Poka-yoke - Adding a confirmation before running kubectl commands in production
February 22, 2025
Poka-yoke
Poka-yoke is the idea of mistake-proofing. It comes from the Toyota Production System and is the idea that you intentionally add a constraint to a process to prevent human error.
Some common examples are a manual transmission car only starting when the clutch is pressed and a microwave only running when the door is closed.
Kubectl Confirm Prompt
I wanted to apply this idea to the kubectl
command when running commands that can change resources in a production environment.
I've found it too easy to run an apply
command in the wrong context and wanted to ensure that couldn't happen.
My requirements were:
- A prompt that warns you that you are running the command in production.
- A confirmation requiring input similar to installing dependencies through a package manager.
- The check does not run on informational commands like
get
anddescribe
. - The check only runs in a specified context (production)
The following is the Zsh function that I was able to piece together. This setup correctly preserves kubectl
tab completion.
This has been working for my needs but may grow if I need to exclude more commands.