Difference between revisions of "Merge multiple kubeconfigs"

From wikieduonline
Jump to navigation Jump to search
Line 1: Line 1:
 
Merge multiple <code>[[~/.kube/config]]</code> into one using <code>[[kubectl konfig merge]]</code>
 
Merge multiple <code>[[~/.kube/config]]</code> into one using <code>[[kubectl konfig merge]]</code>
 +
  
 
1) Make a backup of your current <code>[~/.kube/config]]</code>
 
1) Make a backup of your current <code>[~/.kube/config]]</code>
 
:<code>cp [[~/.kube/config]] ~/.kube/config.BAK.$([[date '+%Y-%m-%d_%H%M']])</code>
 
:<code>cp [[~/.kube/config]] ~/.kube/config.BAK.$([[date '+%Y-%m-%d_%H%M']])</code>
  [[kubectl konfig]] merge file1.yml file2.yml > merged_kubeconfig.yml
+
 
 +
2) Use <code>[[kubectl konfig merge]]</code> for merge files:
 +
  [[kubectl konfig merge]] kubeconfig1.yml kubeconfig2.yml > merged_kubeconfig
  
 
  for CLUSTER in $([[rancher cluster ls]] | grep -v NAME | cut -d"*" -f2- | awk '{print $3}' ); do [[rancher cluster kubeconfig]] $CLUSTER > $CLUSTER.kubeconfig; done
 
  for CLUSTER in $([[rancher cluster ls]] | grep -v NAME | cut -d"*" -f2- | awk '{print $3}' ); do [[rancher cluster kubeconfig]] $CLUSTER > $CLUSTER.kubeconfig; done

Revision as of 09:48, 12 January 2024

Merge multiple ~/.kube/config into one using kubectl konfig merge


1) Make a backup of your current [~/.kube/config]]

cp ~/.kube/config ~/.kube/config.BAK.$(date '+%Y-%m-%d_%H%M')

2) Use kubectl konfig merge for merge files:

kubectl konfig merge kubeconfig1.yml kubeconfig2.yml > merged_kubeconfig
for CLUSTER in $(rancher cluster ls | grep -v NAME | cut -d"*" -f2- | awk '{print $3}' ); do rancher cluster kubeconfig $CLUSTER > $CLUSTER.kubeconfig; done

Related

  • date: date '+%Y-%m-%d_%H%M'

See also

Advertising: