Today we had to work on switching between two kubernetes clusters. The commands of the day are:
1 2 |
kubectl config get-contexts kubectl config use-context <context> |
It’s surprisingly not so simple. Perhaps there are tools out there that people know of to make it easier? What I’ve been doing is taking to ~/.kube/config files and concatenating them together. As an example, my config file looks as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
apiVersion: v1 clusters: - cluster: certificate-authority-data: blahblah... server: https://172.28.225.133:6443 name: bm - cluster: certificate-authority-data: blahblah... server: https://10.93.140.127:6443 name: ccp contexts: - context: cluster: bm user: kubernetes-admin name: bm - context: cluster: ccp user: kubernetes-admin1 name: ccp current-context: ccp kind: Config preferences: {} users: - name: kubernetes-admin user: client-certificate-data: blahblah... client-key-data: blahblah... token: blahblah... - name: kubernetes-admin1 user: client-certificate-data: blahblah... client-key-data: blahblah... token: blahblah... |
Notice how we combine them together. Then I can switch contexts using the commands above. I’ll have ccp or bm.