Hacker News new | ask | show | jobs
by physicles 637 days ago
We’ve basically solved this where I work, with these steps:

- Each environment gets its own directory. We use kustomize to share config between environments.

- direnv “sets” the current context when you cd under a cluster’s directory (it sets an environment variable that a kubectl alias uses. Nobody calls kubectl directly; it wouldn’t work because we’ve banned the current context from the yaml files). You switch clusters by changing to that cluster’s directory.

- most of the time, the only command you run is ‘make’ which just does kubectl kustomize apply (or whatever). 100% of cluster config is checked into git (with git-crypt for secrets), so the worst that can happen is that you reapply something that’s already there.

I’ve also colored the command prompt according to the current cluster.

But anyway it’s essentially impossible to apply a config change to the wrong cluster. I haven’t worried about this in years.

1 comments

what if you forget to run direnv the second time?
You don't have to run anything. The point of direnv is that loads/unloads automatically when your enter/leave a directory
I imagine they use an alias or bash function for cd, which uses direnv under the hood
Yep. Direnv inserts itself into your prompt function.