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
Add kubectl config merge
command
#46381
Comments
@nikhiljindal @madhusudancs can you take a look? |
Can
|
cc @kubernetes/sig-cli-feature-requests |
@madhusudancs @superbrothers @henriquetruta |
@shiywang it is up to SIG-CLI to decide. |
@madhusudancs sure, we'll wait for @kubernetes/sig-cli-maintainers to decide. |
@shiywang thanks! I've already started to implement it here |
/sub |
Issues go stale after 90d of inactivity. Prevent issues from auto-closing with an If this issue is safe to close now please do so with Send feedback to sig-testing, kubernetes/test-infra and/or |
/remove-lifecycle stale |
@superbrothers commented on May 25, 2017, 7:27 AM GMT+2:
works, except the fact your yaml config starts with |
Does not have a yaml config starting with |
well, that almost worked for me, except that... only partial content was copied ! (writing while reading seemed to have messed up the final output !)
|
Issues go stale after 90d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
/remove-lifecycle stale |
Issues go stale after 90d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
/remove-lifecycle stale |
There is a problem that KUBECONFIG does not understands special chars like ~ (home dir path) so use full path. for example: KUBECONFIG=/home/serra/.kube/config:/home/serra/.kube/config.baremetal kubectl config view --flatten > /home/serra/.kube/config |
Most shells expand that for you:
|
My little bash script based on #46381 (comment) # ~/.bashrc
function kmerge() {
KUBECONFIG=~/.kube/config:$1 kubectl config view --flatten > ~/.kube/mergedkub && mv ~/.kube/mergedkub ~/.kube/config
} |
|
Issues go stale after 90d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
Stale issues rot after 30d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
This does not seem to work if you have the same user but different token for the user for different clusters. The |
Rotten issues close after 30d of inactivity. Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
@fejta-bot: Closing this issue. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
Can this be re-opened? The workaround is nice, but a built-in supported command would be way better. |
/reopen |
@0xErnie: You can't reopen an issue/PR unless you authored it or you are a collaborator. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
Running into the same issue as above: The kubectl config view --flatten will only keep the user and token for the first one it encounters, which defeats the purpose of trying to merge it in the first place. This is really annoying since its best practice to use unique tokens/accounts on different clusters, but this command is truncating them when trying to merge multiple accounts/contexts into one file. |
It keeps all uniquely named users/clusters. If you have user stanzas with the same name, keeping all of them would make the resulting file ambiguous.
|
So how can you merge multiple files that have the same username but different tokens? |
you cannot; those are effectively the same user stanza, and can only have a single bearer token |
So if you run multiple clusters you should use a different/unique username on each? Very unintuitive. |
If you want to merge them into a single kubeconfig, yes |
It's possible to specify multiple kubeconfig files via `KUBECONFIG`, for example: `KUBECONFIG=~/cluster1.yaml:~/cluster2.yaml` See kubernetes/kubernetes#46381 (comment) This commit ensures kuberlr can handle this special case in the same way as kubectl does.
as a note for others who are looking for an option to do this, there is now a tool to achieve this, also available as a krew plugin https://github.com/corneliusweig/konfig |
gcloud
/GKE has an efficient way of getting credentials from somewhere by using theget-credentials
command that automatically merges the content of a remote cluster in a local kubeconfig file. We want to have something similar in k8s. A first approach would be having two kubeconfig files locally and being able to merge the content of one into the other without needing to do manual copy/paste.We could have a command that looks like:
kubectl config merge <source> <target>
Where the
target
file defaults to~/.kube/config
andsource
would be some kubeconfig file that the user wants to have its entries (users, contexts and clusters) copied to thetarget
file.If there is no name conflict, i.e., the entries in
source
don’t exist intarget
, the output is quite straightforward. However, if there is some conflict, we need to decide on how to approach. Do anything and inform the user? Rename them in target? Copy only those with no conflict? Have this options as parameters (--ignore, --rename, --abort-if-conflict
, etc)I suggest having for now, for the sake of simplicity doing anything and informing the user. The others can me made in follow-up issues
The text was updated successfully, but these errors were encountered: