Difference between revisions of "Merge multiple kubeconfigs"
Jump to navigation
Jump to search
(10 intermediate revisions by the same user not shown) | |||
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> | |
+ | |||
+ | 2) Use <code>[[kubectl konfig merge]]</code> for merge files: | ||
+ | :<code>[[kubectl konfig merge]] ~/.kube/config yournewcluster-configfile > merged_kubeconfig</code> | ||
+ | |||
+ | 3) Overwrite your old ~/.kube/config with your new file | ||
+ | :<code>cp merged_kubeconfig ~/.kube/config</code> | ||
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 | ||
Line 9: | Line 15: | ||
== Related == | == Related == | ||
* <code>[[date]]: date '+%Y-%m-%d_%H%M'</code> | * <code>[[date]]: date '+%Y-%m-%d_%H%M'</code> | ||
+ | * <code>[[kubectl config get-contexts]]</code> | ||
+ | * <code>[[kubectl config use-context]]</code> | ||
== See also == | == See also == |
Latest revision as of 10:32, 24 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 ~/.kube/config yournewcluster-configfile > merged_kubeconfig
3) Overwrite your old ~/.kube/config with your new file
cp merged_kubeconfig ~/.kube/config
for CLUSTER in $(rancher cluster ls | grep -v NAME | cut -d"*" -f2- | awk '{print $3}' ); do rancher cluster kubeconfig $CLUSTER > $CLUSTER.kubeconfig; done
Related[edit]
date: date '+%Y-%m-%d_%H%M'
kubectl config get-contexts
kubectl config use-context
See also[edit]
Advertising: