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.

  • Can you provide the output of kubectl config view? – A. Darwin Nov 21 '22 at 15:12
  • I can't really do that, but the very weird thing is, other clusters have the following properties : name, server, and certificate-authority-data. but the cluster that I want to have its pods showing, only has name and server, where the server is empty, and the name showing just the cluster name ex : my_test_cluster. where as the others show like : gke_projectname_zone_cluster-name – jaafar Nasrallah Nov 21 '22 at 15:20
  • @A.Darwin thank you for your answer, but the above comment still puzzles me and I don't thing it qualifies to be a full post – jaafar Nasrallah Nov 21 '22 at 15:25

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
  • 582
  • 2
  • 7