Re: [kubernetes/kubernetes] Add `kubectl config merge` command (#46381)

5 views
Skip to first unread message

Madhusudan.C.S

unread,
May 25, 2017, 2:45:53 AM5/25/17
to kubernetes/kubernetes, k8s-mirror-cli-feature-requests, Team mention

kubectl config view might not work as is as it redacts certificate data. kubectl config view --flatten might, but I have never tried that with multiple kubeconfigs.

cc @kubernetes/sig-cli-feature-requests


You are receiving this because you are on a team that was mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.

Shiyang Wang

unread,
May 25, 2017, 3:19:41 AM5/25/17
to kubernetes/kubernetes, k8s-mirror-cli-feature-requests, Team mention

@madhusudancs @superbrothers
KUBECONFIG=~/.kube/config:~/config kubectl config view --flatten works, but I think adding this kubectl config merge is also ok, I can implement this since I'm working on another kubectl config subcommand
cc @kubernetes/sig-cli-feature-requests

Madhusudan.C.S

unread,
May 25, 2017, 4:35:11 AM5/25/17
to kubernetes/kubernetes, k8s-mirror-cli-feature-requests, Team mention

@shiywang it is up to SIG-CLI to decide.

Shiyang Wang

unread,
May 25, 2017, 4:39:46 AM5/25/17
to kubernetes/kubernetes, k8s-mirror-cli-feature-requests, Team mention

@madhusudancs sure, we'll wait for @kubernetes/sig-cli-maintainers to decide.

Henrique

unread,
May 25, 2017, 2:29:06 PM5/25/17
to kubernetes/kubernetes, k8s-mirror-cli-feature-requests, Team mention

@shiywang thanks! I've already started to implement it here

Brian Grant

unread,
Jun 20, 2017, 9:14:43 PM6/20/17
to kubernetes/kubernetes, k8s-mirror-cli-feature-requests, Team mention

See also #9298, #10693, #20605, #30395

Chao Xu

unread,
Aug 9, 2017, 6:35:35 PM8/9/17
to kubernetes/kubernetes, k8s-mirror-cli-feature-requests, Team mention

/sub

fejta-bot

unread,
Jan 2, 2018, 12:04:37 PM1/2/18
to kubernetes/kubernetes, k8s-mirror-cli-feature-requests, Team mention

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

Prevent issues from auto-closing with an /lifecycle frozen comment.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or @fejta.
/lifecycle stale

salmicrosoft

unread,
Jan 23, 2018, 7:35:50 PM1/23/18
to kubernetes/kubernetes, k8s-mirror-cli-feature-requests, Team mention

/remove-lifecycle stale

Paul Charlton

unread,
Mar 7, 2018, 9:07:46 AM3/7/18
to kubernetes/kubernetes, k8s-mirror-cli-feature-requests, Team mention

Petr Michalec

unread,
Mar 16, 2018, 4:44:43 PM3/16/18
to kubernetes/kubernetes, k8s-mirror-cli-feature-requests, Team mention

@superbrothers commented on May 25, 2017, 7:27 AM GMT+2:

Can kubectl config view meet your requirements?

# use multiple kubeconfig files at the same time and view merged config
$ KUBECONFIG=~/.kube/config:~/.kube/kubconfig2 kubectl config view

https://kubernetes.io/docs/user-guide/kubectl-cheatsheet/

works, except the fact your yaml config starts with --- 👎

David Lewis

unread,
Mar 16, 2018, 6:01:40 PM3/16/18
to kubernetes/kubernetes, k8s-mirror-cli-feature-requests, Team mention

@epcim

KUBECONFIG=~/.kube/config:~/.kube/kubconfig2 kubectl config view --flatten > ~/.kube/config

Does not have a yaml config starting with ---, however, it still works even when yaml starts with that separator.

Anthony Dahanne

unread,
Apr 9, 2018, 3:09:44 PM4/9/18
to kubernetes/kubernetes, k8s-mirror-cli-feature-requests, Team mention

KUBECONFIG=/.kube/config:/.kube/kubconfig2 kubectl config view --flatten > ~/.kube/config

well, that almost worked for me, except that... only partial content was copied ! (writing while reading seemed to have messed up the final output !)
I had better luck with a temporary file :

KUBECONFIG=~/.kube/config:~/.kube/kubconfig2 kubectl config view --flatten > mergedkub && mv mergedkub ~/.kube/config

fejta-bot

unread,
Jul 8, 2018, 3:18:36 PM7/8/18
to kubernetes/kubernetes, k8s-mirror-cli-feature-requests, Team mention

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

Anthony Dahanne

unread,
Jul 8, 2018, 9:37:04 PM7/8/18
to kubernetes/kubernetes, k8s-mirror-cli-feature-requests, Team mention

/remove-lifecycle stale

fejta-bot

unread,
Oct 6, 2018, 10:20:12 PM10/6/18
to kubernetes/kubernetes, k8s-mirror-cli-feature-requests, Team mention

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.

/lifecycle stale

Rémy Léone

unread,
Oct 7, 2018, 4:13:13 AM10/7/18
to kubernetes/kubernetes, k8s-mirror-cli-feature-requests, Team mention

/remove-lifecycle stale

omerfsen

unread,
Dec 18, 2018, 2:28:19 PM12/18/18
to kubernetes/kubernetes, k8s-mirror-cli-feature-requests, Team mention

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

Jordan Liggitt

unread,
Dec 18, 2018, 2:35:44 PM12/18/18
to kubernetes/kubernetes, k8s-mirror-cli-feature-requests, Team mention

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:

$ more ~/k1
apiVersion: v1
clusters:
- cluster:
    server: https://1.1.1.1
  name: cluster1
contexts:
- context:
    cluster: cluster1
    user: user1
  name: context1
current-context: context1
kind: Config
preferences: {}
users:
- name: user1

$ more ~/k2
apiVersion: v1
clusters:
- cluster:
    server: https://2.2.2.2
  name: cluster2
contexts:
- context:
    cluster: cluster2
    user: user2
  name: context2
current-context: context2
kind: Config
preferences: {}
users:
- name: user2

$ KUBECONFIG=~/k1:~/k2 kubectl config view
apiVersion: v1
clusters:
- cluster:
    server: https://1.1.1.1
  name: cluster1
- cluster:
    server: https://2.2.2.2
  name: cluster2
contexts:
- context:
    cluster: cluster1
    user: user1
  name: context1
- context:
    cluster: cluster2
    user: user2
  name: context2
current-context: context1
kind: Config
preferences: {}
users:
- name: user1
  user: {}
- name: user2
  user: {}

Michael

unread,
Feb 7, 2019, 7:45:30 AM2/7/19
to kubernetes/kubernetes, k8s-mirror-cli-feature-requests, Team mention

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
}

Drew Wells

unread,
Apr 5, 2019, 1:26:02 PM4/5/19
to kubernetes/kubernetes, k8s-mirror-cli-feature-requests, Team mention

kubectl config merge would be easier to remember. First class support would be nice even though the workaround is clever

fejta-bot

unread,
Jul 4, 2019, 1:34:30 PM7/4/19
to kubernetes/kubernetes, k8s-mirror-cli-feature-requests, Team mention

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

fejta-bot

unread,
Aug 3, 2019, 2:23:12 PM8/3/19
to kubernetes/kubernetes, k8s-mirror-cli-feature-requests, Team mention

Stale issues rot after 30d of inactivity.
Mark the issue as fresh with /remove-lifecycle rotten.
Rotten issues close after an additional 30d of inactivity.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.

/lifecycle rotten

eroji

unread,
Aug 30, 2019, 9:16:34 PM8/30/19
to kubernetes/kubernetes, k8s-mirror-cli-feature-requests, Team mention

This does not seem to work if you have the same user but different token for the user for different clusters. 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.

fejta-bot

unread,
Sep 29, 2019, 10:00:28 PM9/29/19
to kubernetes/kubernetes, k8s-mirror-cli-feature-requests, Team mention

Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.


Mark the issue as fresh with /remove-lifecycle rotten.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/close

Kubernetes Prow Robot

unread,
Sep 29, 2019, 10:00:49 PM9/29/19
to kubernetes/kubernetes, k8s-mirror-cli-feature-requests, Team mention

Closed #46381.

Kubernetes Prow Robot

unread,
Sep 29, 2019, 10:00:53 PM9/29/19
to kubernetes/kubernetes, k8s-mirror-cli-feature-requests, Team mention

@fejta-bot: Closing this issue.

In response to this:

Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Mark the issue as fresh with /remove-lifecycle rotten.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/close

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.

Phillip Prescher

unread,
Oct 27, 2019, 6:27:41 PM10/27/19
to kubernetes/kubernetes, k8s-mirror-cli-feature-requests, Team mention

Can this be re-opened? The workaround is nice, but a built-in supported command would be way better.


You are receiving this because you are on a team that was mentioned.

Reply to this email directly, view it on GitHub, or unsubscribe.

Alexander Kauerz

unread,
Nov 4, 2019, 9:13:23 AM11/4/19
to kubernetes/kubernetes, k8s-mirror-cli-feature-requests, Team mention

/reopen

Kubernetes Prow Robot

unread,
Nov 4, 2019, 9:13:48 AM11/4/19
to kubernetes/kubernetes, k8s-mirror-cli-feature-requests, Team mention

@0xErnie: You can't reopen an issue/PR unless you authored it or you are a collaborator.

In response to this:

/reopen

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.

richstokes

unread,
Nov 12, 2019, 5:36:10 PM11/12/19
to kubernetes/kubernetes, k8s-mirror-cli-feature-requests, Team mention

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, but this command is truncating them when trying to merge multiple accounts/contexts into one file.

Jordan Liggitt

unread,
Nov 12, 2019, 5:46:21 PM11/12/19
to kubernetes/kubernetes, k8s-mirror-cli-feature-requests, Team mention

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.

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.

richstokes

unread,
Nov 12, 2019, 5:49:48 PM11/12/19
to kubernetes/kubernetes, k8s-mirror-cli-feature-requests, Team mention

So how can you merge multiple files that have the same username but different tokens?

Jordan Liggitt

unread,
Nov 12, 2019, 5:51:11 PM11/12/19
to kubernetes/kubernetes, k8s-mirror-cli-feature-requests, Team mention

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

richstokes

unread,
Nov 12, 2019, 5:53:49 PM11/12/19
to kubernetes/kubernetes, k8s-mirror-cli-feature-requests, Team mention

So if you run multiple clusters you should use a different/unique username on each? Very unintuitive.

Jordan Liggitt

unread,
Nov 12, 2019, 6:24:35 PM11/12/19
to kubernetes/kubernetes, k8s-mirror-cli-feature-requests, Team mention

If you want to merge them into a single kubeconfig, yes

Adil H

unread,
Oct 29, 2020, 8:09:44 AM10/29/20
to kubernetes/kubernetes, k8s-mirror-cli-feature-requests, Team mention

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

Reply all
Reply to author
Forward
0 new messages