-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Go] does not work with multiple kubeconfig files (e.g. KUBECONFIG=c1:c2) #211
Comments
Yeah this is a major point not implemented in Go version yet as I’m not fully sure how to do it in terms of modifying files when there are multiple of them (which one do you set current-context on). I will pin this issue as others will most likely hit it too. |
so I've only been using k8s for about 4 months now so I'm still learning(probably never stop) but I'm still trying to wrap my head around the config files especially when you have more than 1, they can be merged in memory and that's what I've used I will just try and merge them all to a single file and export that to $KUBECONFIG, there is a --raw or --flatten option?? |
Yes, they can be merged in-memory or into a file. Read https://ahmet.im/blog/mastering-kubeconfig/. However, in this situation I need to study how to modify which file when user specifies |
thanks I'll have a look |
btw awesome work!!! |
I dug through kubectl and saw that it uses this to get the config file to write current context into. Here I tried to add multiple kubeconfig support quickly, seems working but not sure if it's good enough for a PR or if you'd be interested with such a big one. Actually it looks bigger than it is because I had to move somethings around because of a cyclic dependency. |
@sedooe This is useful :) Are you planning to create a PR? |
I use the kubecctx to manage multiple files. However, I'd rather see this in kubectx. |
Hello,
Do you list somewhere the improvements needed to have a PR good enough ? Best |
we need:
|
read above @willzhang:
|
thanks,it's useful , but user must different in each kubeconfig
|
What you want is a tool to wrangle kubeconfig. Kubectx is only for switching "context"s. https://krew.sigs.k8s.io/plugins/ has plenty of plugins like |
In the meantime, could the behaviour here just be the same as the bash version? ie: just set the context on the first file. This would at least make the go version backwards compatible, and tricks like having a temp kubeconfig file would still work. Happy to raise a PR to do so if it seems worthwhile. |
requires switching to the bash version of kubectx because this is not yet supported by the golang version see ahmetb/kubectx#211
If multiple kubeconfig are merged into one according to @willzhang , I can use I add following alias to ~/.bash_profile:
I wander whtat's the value of kubectx on contexts management? |
Sure, for me, typing kctx and picking the context from a quick pop up menu is much easier than typing out the name of the context. |
Best effort is good enough for most cases. We assume, altought there are multiple ctx across multiple files, every one is named unique. As long as there are no conflicting names it's not an problem.
I don't see a problem adding new, non conflicting data from other .kubeconfigs to the main config. |
Since there appears to be not much happening here: I stumbled across this today. Very sad that the Go version doesn't implement this yet. The packaging of my distro (NixOS) no longer provides for the bash script version of kubectx. Love to see this getting added in the not so distant future. |
For folks finding this who are wondering how to still use kubectx when you have lots of kubeconfig files, here's an example for your .zshrc file to generate a KUBECONFIG variable that kubectx can read. #Lots of kubeconfig files!
# If there's already a kubeconfig file in ~/.kube/config it will import that too and all the contexts
DEFAULT_KUBECONFIG_FILE="$HOME/.kube/config"
if test -f "${DEFAULT_KUBECONFIG_FILE}"
then
export KUBECONFIG="$DEFAULT_KUBECONFIG_FILE"
fi
# Your additional kubeconfig files should be inside ~/.kube/ and named kubeconfig.*.yml or kubeconfig.*.yaml
OIFS="$IFS"
IFS=$'\n'
for kubeconfigFile in `find "$HOME/.kube/" -type f -name "kubeconfig.*.yml" -o -name "kubeconfig.*.yaml"`
do
export KUBECONFIG="$kubeconfigFile:$KUBECONFIG"
done
IFS="$OIFS" I also find myself using kubie when I need to lock a particular session to a specific kubeconfig context/namespace. It's not as quick as kctx, but the session you set up with kubie will stay on that kubeconfig even if you use kctx to change it everywhere else. |
Your solution does not work for me or maybe I miss something?
Can you please provide an example of the |
due to an issue with kubectx (ahmetb/kubectx#211) I need to switch to a single kubeconfig keeping multiple kubeconfig collection … will need it when a new config is added … in this case: - add new kubeconfig to ~/.kube - switch to the multi-config KUBECONFIG and apply - run `kubectl config view --flatten > ~/.kube/config` - change back to the single-config KUBECONFIG and apply
Easy workaround based on this StackOverflow answer. Write your different configs in multiple files and merge them whenever you need, for instance with the following in your
This will export a merged configuration to
|
year 2024, that's sad :( I've been using
And today I was surprised to discover that brew brew-installed kubectx is actually a bash flavor, when my go-flavor install on linux has failed with multiple kubeconfig files. |
I removed the bash version and installed the go version on ubuntu and now I am receiving the error message "kubeconfig error: failed to load: cannot determine kubeconfig path: multiple files in KUBECONFIG are currently not supported"
The text was updated successfully, but these errors were encountered: