ajoy sinha
ajoy sinha

Reputation: 1236

Issue on GCP Kubernetes cluster connectivity from local (Windows 10)

I have two projects in GCP i.e. Project A and Project B. Project A has Cluster CA and Project B has Cluster CB. Now I have configured my local environment [ Windows 10 ] with Gcloud CLI and Kubetel to connect to environment. Usigng "gcloud init" command I am able to initialize context and able to connect to Project A and Cluster CA. and on executing "kubectl get pods" showing the pods in cluster CA. Now I am trying to connect Cluster CB in project B. I am doing "gcloud init" re-configuration and selecting Project B. but now when I am executing "kubectl get pods", system is showing pods from cluster CA not from cluster CB. Could you please help me with the steps to connect and get the details from cluster CB

C:\Program Files (x86)\Google\Cloud SDK>gcloud init
Welcome! This command will take you through the configuration of gcloud.

Settings from your current configuration [default] are:
accessibility:
  screen_reader: 'True'
core:
  account: [email protected]
  disable_usage_reporting: 'True'
  project: Project B

Pick configuration to use:
 [1] Re-initialize this configuration [default] with new settings
 [2] Create a new configuration
Please enter your numeric choice:  1

Your current configuration has been set to: [default]

You can skip diagnostics next time by using the following flag:
  gcloud init --skip-diagnostics

Network diagnostic detects and fixes local network connection issues.
Checking network connection...done.
Reachability Check passed.
Network diagnostic passed (1/1 checks passed).

Choose the account you would like to use to perform operations for this configuration:
 [1] [email protected]
 [2] Log in with a new account
Please enter your numeric choice:  1

You are logged in as: [[email protected]].

Pick cloud project to use:
 [1] PROJECT A
 [2] PROJECT B
 [3] Enter a project ID
 [4] Create a new project
Please enter numeric choice or text value (must exactly match list item):  2

Your current project has been set to: [PROJECT B].

Do you want to configure a default Compute Region and Zone? (Y/n)?  n

Your Google Cloud SDK is configured and ready to use!

* Commands that require authentication will use [email protected] by default
* Commands will reference project `PROJECT B` by default
Run `gcloud help config` to learn how to change individual settings

This gcloud configuration is called [default]. You can create additional configurations if you work with multiple accounts and/or projects.
Run `gcloud topic configurations` to learn more.

Some things to try next:

* Run `gcloud --help` to see the Cloud Platform services you can interact with. And run `gcloud help COMMAND` to get help on any gcloud command.
* Run `gcloud topic --help` to learn about advanced features of the SDK like arg files and output formatting
* Run `gcloud cheat-sheet` to see a roster of go-to `gcloud` commands.

C:\Program Files (x86)\Google\Cloud SDK>kubectl get pods
NAME                        READY   STATUS    RESTARTS   AGE
metabase                    1/1     Running   0          3d19h
mongodb                     1/1     Running   0          4d

C:\Program Files (x86)\Google\Cloud SDK>

Upvotes: 1

Views: 70

Answers (1)

Harsh Manvar
Harsh Manvar

Reputation: 30160

Kubernetes get auth by .kube/config file, what you are updating is gcloud auth or changing the project but not changing the context for the kubectl

This command will list the available cluster to connect if added any

kubectl config get-contexts

Change the context to another cluster

kubectl config use-context <cluster-name or context shown above>

If context is not available after gcloud auth you did you have to run the command to set/add kubeconfig file

gcloud container clusters get-credentials <cluster-name>

refer doc for more

Upvotes: 1

Related Questions