'Commands to switch kubectl and gcloud back and forth between two totally separate projects
Edit/Update: I should have noted, that for both of these clients/projects, I do have 2 separate Gmail accounts ([email protected] and [email protected]).
I am a freelancer that is new to K8s and GCP. I happen to be on two separate projects that just started using both of these technologies around the same time, and I am trying to manage clusters and projects from both of these clients from the same laptop. I want to be able to switch back and forth between each client and their respective K8s/GCP project and I'm looking for a list of all the kubectl and gcloud commands for doing this back and forth switchback.
So to reiterate:
- Client #1
- project ABC
- Client #2
- project DEF
Locally when I run kubectl config get-clusters I see:
docker-desktop
gke_client-1-proj-abc-dev
gke_client-2-proj-def-dev
minikube
Where gke_client-1-proj-abc-dev is Client #1 (project ABC)'s dev environment K8s cluster, and where gke_client-2-proj-def-dev is Client #2 (project DEF)'s dev K8s cluster.
However when I run:
gcloud projects list
PROJECT_ID NAME PROJECT_NUMBER
client-1-proj-abc Client 1 Proj ABC Local 12345 (omitting actual project #s for brevity)
client-1-proj-abc-dev Client 1 Proj ABC Dev 23456
client-1-proj-abc-qa Client 1 Proj ABC QA 34567
So it appears the kubectl is correctly "connected" to both client projects, but gcloud is only logged-in/authenticated/connected to Client #1 and not Client #2.
Either way, I'm looking for the exact commands I can use so that:
- when I'm "connected to" (pointing at) Client #1, all
gcloudandkubectlcommands are scoped to them and their project; and - when I'm "connected to" (pointing at) Client #2, all
gcloudandkubectlcommands are scoped to them and their project; and - there's an easy way for me to tell which client/project/cluster I'm "connected to" so that I don't inadvertently run
kubectlandgcloudcommands intended for one client, but actually muck up the clusters of another
Thanks in advance for any and all help.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
