Search code examples
google-kubernetes-engine

How can I switch between Google Kubernetes Engine (GKE) clusters with kubectl?


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?


Solution

  • For me works this:

    1. Login
    gcloud auth application-default login
    
    1. Switch to the project
    gcloud config set project <your-project-name>
    
    1. List available clusters
    gcloud container clusters list
    
    1. Get the cluster credentials
    gcloud container clusters get-credentials <cluster-name> --region <cluster-region>
    

    Then I was able to switch the context of kubectl