Working with multiple Kubernetes Clusters on Azure Container Service

When using multiple Kubernetes clusters on Azure Container Service, I see people executing the az acs kubernetes get-credentials command every time they need to reconnect to a different cluster. This works, but is not needed. You can do it easier.

To get access to a Kubernetes cluster hosted on Azure Container Service you get access with the following command:
az acs kubernetes get-credentials –resource-group=myresourcegroup –name=myacscluster –ssh-key-file “C:\privatekeyopenssl”

The –ssh-key-file is optional. If you leave it, your ssh file should be located in c:\users\yourname\.ssh . To read more about the ssh file, read my blogpost about it.

When you execute the command above, a config file is written to c:\users\yourname\.kube

When you want a connection to a different Kubernetes Cluster on Azure Container Service you execute the az acs kubernetes get-credentials command again, but with the correct parameters ofcourse:
az acs kubernetes get-credentials –resource-group=myotherresourcegroup –name=myotheracscluster –ssh-key-file “C:\otherprivatekeyopenssl”

This second command edits the existing config file. Now the config file contains both clusters and the corresponding contexts. You can open the file to see it, but also request the contexts in the command prompt with:
kubectl config get-contexts
This results in:
output

The asterisk marks the current context you are working on now.
When you want to switch contexts, execute:
kubectl config use-context mycluster-master
output2

Now you are connected to the other context.
So no need to execute az acs kubernetes get-credentials again.

 

Advertenties

Geef een reactie

Vul je gegevens in of klik op een icoon om in te loggen.

WordPress.com logo

Je reageert onder je WordPress.com account. Log uit /  Bijwerken )

Google+ photo

Je reageert onder je Google+ account. Log uit /  Bijwerken )

Twitter-afbeelding

Je reageert onder je Twitter account. Log uit /  Bijwerken )

Facebook foto

Je reageert onder je Facebook account. Log uit /  Bijwerken )

w

Verbinden met %s