Last active
April 6, 2021 10:02
-
-
Save mtilson/c1faf48e43a0a9f07d0b91bab1b1ab66 to your computer and use it in GitHub Desktop.
how to merge kubeconfig files [k8s]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cd $(mktemp -d) | |
# `./config` - existent kubeconfig to merge to (like ~/.kube/config) | |
# `./configToAdd` - new kubeconfig to merge from | |
cat <<_EOF_ > ./config | |
apiVersion: v1 | |
clusters: | |
- cluster: | |
certificate-authority-data: MQo= | |
server: https://K8S-DOMAIN-NAME-1 | |
name: CLUSTER-1 | |
- cluster: | |
certificate-authority-data: Mgo= | |
server: https://K8S-DOMAIN-NAME-2 | |
name: CLUSTER-2 | |
contexts: | |
- context: | |
cluster: CLUSTER-1 | |
namespace: default | |
user: USER-1 | |
name: CONTEXT-1 | |
- context: | |
cluster: CLUSTER-2 | |
namespace: default | |
user: USER-2 | |
name: CONTEXT-2 | |
current-context: CONTEXT-1 | |
kind: Config | |
preferences: {} | |
users: | |
- name: USER-1 | |
user: | |
exec: | |
args: null | |
command: aws | |
env: null | |
provideClusterInfo: false | |
- name: USER-2 | |
user: | |
exec: | |
args: null | |
command: aws | |
env: null | |
provideClusterInfo: false | |
_EOF_ | |
cat <<_EOF_ > ./configToAdd | |
apiVersion: v1 | |
clusters: | |
- cluster: | |
certificate-authority-data: Mwo= | |
server: https://K8S-DOMAIN-NAME-3 | |
name: CLUSTER-3 | |
contexts: | |
- context: | |
cluster: CLUSTER-3 | |
namespace: default | |
user: USER-3 | |
name: CONTEXT-3 | |
current-context: CONTEXT-3 | |
kind: Config | |
preferences: {} | |
users: | |
- name: USER-3 | |
user: | |
exec: | |
args: null | |
command: aws | |
env: null | |
provideClusterInfo: false | |
_EOF_ | |
KUBECONFIG=./config:./configToAdd kubectl config view --flatten | sponge ./config | |
# `./config` now contains both initial and merged data |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment