The official kubernetes documentation already provides a good documentation on configuring access to multiple clusters.
After following their guide, I could list multiple cluster configurations:
$ kubectl config get-contexts CURRENT NAME CLUSTER AUTHINFO NAMESPACE kind-kind kind-kind kind-kind * kubernetes-admin@kubernetes-nextlayer kubernetes-nextlayer kubernetes-admin kubernetes-admin@kubernetes-office kubernetes-office kubernetes-admin
I already named them differently to make sure they all show up. Every time I tried to get the nodes I received following error:
$ kubectl get nodes error: You must be logged in to the server (Unauthorized)
The short answer is: No
kubectl uses first matching credentials that match your configured
kubernetes-admin in all your configs. Authinfos are not internally namespaced by cluster name. So I always received the error above. (Unauthorized) I needed to also rename the
$ kubectl config get-contexts CURRENT NAME CLUSTER AUTHINFO NAMESPACE kind-kind kind-kind kind-kind * kubernetes-admin@kubernetes-nextlayer kubernetes-nextlayer kubernetes-admin-nextlayer kubernetes-admin@kubernetes-office kubernetes-office kubernetes-admin-office
As soon as each cluster had a unique
AUTHINFO everything worked like a charm.
If you have any questions, just hit me up on Twitter:
Todays #kubernetes learning: AUTHINFOS for different kubernetes contexts are not namespaced - so you need to name them differently:
— Philip Miglinci (@pmigat)