From the Google Cloud Shell, when I run kubectl
I am running it on the GKE cluster ( cluster-1
) from my previous project ( my-project-1
). I would like to run it on the gke cluster ( cluster-2
) in my new project ( my-project-2
).
How can I update my context to use the new cluster?
For me works this:
gcloud auth application-default login
gcloud config set project <your-project-name>
gcloud container clusters list
gcloud container clusters get-credentials <cluster-name> --region <cluster-region>
Then I was able to switch the context of kubectl
Here are the commands that work for me when I want to switch between clusters:
Check current cluster:
kubectl config current-context
Example output:
my-project-1_us-central1_cluster-1
Switch to a different cluster (replace $CLUSTER_NAME
, $REGION
, and $PROJECT_NAME
with your values):
gcloud container clusters get-credentials $CLUSTER_NAME --region $REGION --project $PROJECT_NAME
Example:
gcloud container clusters get-credentials cluster-2 --region us-central1 --project my-project-2
Confirm you have switched clusters by re-running the current-context
command
kubectl config current-context
Example output:
my-project-2_us-central1_cluster-2
To check what cluster you are currently using:
kubectl config current-context
To check what clusters you have configured:
kubectl config get-contexts
To switch, you have two options:
(Option 1) If you don't have the cluster you to switch to configured, run:
gcloud container clusters get-credentials <cluster-name> --region <cluster-region> --project <project>
(Option 2) Use kubectl to switch context, get <name>
from step 2:
kubectl config use-context <name>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.