1

I am using Google Cloud Platform, and I have two different kubernetes clusters running on GKE. Now these clusters are zonal clusters, and are running on different zones. the issue is when I am using the cloud shell, kubectl get pods is getting pods from another cluster. I have used kubectl config set-cluster xxx to set the cluster, but still, the other pods are showing only.

1 Answers1

1

If kubectl get pods returns pods from another cluster, your kubectl configuration is probably pointing to the other cluster.

You can check the current context (current cluster) kubectl is using with: kubectl config current-context.

Note that, as the GKE documentation highlights:

When you create a cluster using the Google Cloud console or using gcloud CLI from a different computer, your environment's kubeconfig file is not updated. Additionally, if a project team member uses gcloud CLI to create a cluster from their computer, their kubeconfig is updated but yours is not. The kubeconfig entry contains either:

Your credentials as shown in gcloud auth list, or

The application default credentials, if configured.

To generate a kubeconfig context in your environment, ensure that you have the container.clusters.get permission. The least-privileged IAM role that provides this permission is container.clusterViewer.

To generate a kubeconfig context for a specific cluster, run the following command:

gcloud container clusters get-credentials CLUSTER_NAME

Replace CLUSTER_NAME with the name of your cluster.

If the target cluster is not running in the default zone or region, or if you did not set a default zone or region, you need to supply the region (--region=REGION) or zone (--zone=ZONE) in the command.

Note: Running gcloud container clusters get-credentials also changes the current context for kubectl to that cluster.

A. Darwin
  • 632