Skip to main content

Direnv

·156 words·1 min· loading · loading ·
Abhinav.K
Author
Abhinav.K
DevOps, Biker, Hiker, Photography Enthusiast & Sometimes Bathroom Singer

I have recently been introduced to direnv by one of my friends. And boy-oh-boy am I grateful about finding this.

As an infrastructure engineer, my everyday task is to play around with things. Different Kubernetes cluster for example. And creating different commands or aliases to interact with different clusters becomes cumbersome sooner or later. Up until now, what I have been doing is to create my cluster (using k3d or kind) and then create aliases to interact with these cluster changing --kubeconfig option with each.

After configuring .envrc file, now I don’t have to worry about remembering what command I had created.

Here is one sample. This is one of my directories’ layout:

$ tree -a --charset terminal k3d/
k3d/
|-- dev
|   |-- cluster1.yaml
|   `-- .envrc
`-- prod
    |-- cluster2.yaml
    `-- .envrc

2 directories, 4 files

and content of .envrc file looks like this:

$ cat k3d/dev/.envrc
export KUBECONFIG="${HOME}/.config/k3d/kubeconfig-dev-cluster1.yaml"

Util next time… Peace ✌️!