Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set KUBECONFIG environment variable dynamically

Tags:

find

bash

shell

I am quite new to Bash and working on multiple kubernetes cluster. I wanted some kind of utility wherein I can set my KUBECONFIG variable dynamically as I work on multiple clusters. My kubeconfig file lies in multiple folders. What I want is to find all the kubeconfig files , get the paths and concatenate the paths with colon , set it to KUBECONFIG variable and export it in bashrc file.

I know pieces of command but not able to frame full code.

find /Users/anandabhishe/gitlab/ -name kubeconfig.yaml -exec echo {} \; 

I want to concatenate the output of find command and set my KUBECONFIG. like this "

export KUBECONFIG=/Users/anandabhishe/gitlab/work2/kubeconfigs/scdc1-staging-hrwork-dev/kubeconfig.yaml:/Users/anandabhishe/gitlab/work2/kubeconfigs/scdc2-prod-hrwork-uat/kubeconfig.yaml:/Users/anandabhishe/gitlab/work2/kubeconfigs/scdc2-prod-hrwork/kubeconfig.yaml "

like image 574
Ladu anand Avatar asked Mar 12 '26 03:03

Ladu anand


1 Answers

You can try something like that:

export KUBECONFIG=$(for i in $(find /Users/anandabhishe/gitlab/ -iname 'kubeconfig.yaml') ; do echo -n ":$i"; done | cut -c 2-)
like image 97
flutt13 Avatar answered Mar 13 '26 19:03

flutt13



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!