Technology

Kubernetes contexts

Today we had to work on switching between two kubernetes clusters.  The commands of the day are:
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:
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.