0

Weirdly, I am unable to connect to GKE cluster from Local (Mac) via Kubectl, But I can connect from the Google cloud shell? I have fetch the K8s creds which I can see the kubeconfig file, still I am getting timeout. Any suggestions what might be wrong?

$ gcloud components install kubectl


Your current Cloud SDK version is: 367.0.0
Installing components from version: 367.0.0

┌─────────────────────────────────────────────┐
│     These components will be installed.     │
├────────────────────────┬─────────┬──────────┤
│          Name          │ Version │   Size   │
├────────────────────────┼─────────┼──────────┤
│ gke-gcloud-auth-plugin │   0.1.1 │  3.4 MiB │
│ kubectl                │  1.20.8 │ 89.0 MiB │
│ kubectl                │  1.20.8 │  < 1 MiB │
└────────────────────────┴─────────┴──────────┘

For the latest full release notes, please visit:
  https://cloud.google.com/sdk/release_notes

Do you want to continue (Y/n)?  Y

╔════════════════════════════════════════════════════════════╗
╠═ Creating update staging area                             ═╣
╠════════════════════════════════════════════════════════════╣
╠═ Installing: gke-gcloud-auth-plugin                       ═╣
╠════════════════════════════════════════════════════════════╣
╠═ Installing: gke-gcloud-auth-plugin                       ═╣
╠════════════════════════════════════════════════════════════╣
╠═ Installing: kubectl                                      ═╣
╠════════════════════════════════════════════════════════════╣
╠═ Installing: kubectl                                      ═╣
╠════════════════════════════════════════════════════════════╣
╠═ Creating backup and activating new installation          ═╣
╚════════════════════════════════════════════════════════════╝

Performing post processing steps...done.

Update done!


$ gcloud auth login
Your browser has been opened to visit:

    https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=xxxxxxxxxxxxxxxxxxx
You are now logged in as [atul@xxxxx.com].
Your current project is [test-dev-k8s].  You can change this setting by running:

$ gcloud container clusters get-credentials test-dev-k8s-cluster --region asia-south1 --project test-dev-k8s
Fetching cluster endpoint and auth data.
kubeconfig entry generated for test-dev-k8s-cluster.

$ kubectl get ns
Unable to connect to the server: dial tcp 34.93.111.251:443: i/o timeout
Atul Singh
  • 59
  • 1
  • 9

3 Answers3

1

You might want to give a try to this complete cluster configuration access for kubectl, here you can find the steps needed to configure the kubectl in your kubernetes cluster.

If this does not work, here is a post to some other workarounds for the same connectivity issue in the cluster.

Just as information, are you using minikube, docker or just GKE in your deployment?

Vicente Ayala
  • 191
  • 10
1

After analyzing all the Cluster's configurations, I have found that "Control plane authorized networks" was enabled which was actually "Enable control plane authorized networks to block untrusted non-GCP source IPs from accessing the Kubernetes to control plane through HTTPS." and my local IP was obviously non-GCP IP.
Once, I have disabled it, I can connect from my local system.

Atul Singh
  • 59
  • 1
  • 9
0

Login to your GCP account first using the Google Cloud SDK

gcloud auth login 

https://cloud.google.com/sdk/gcloud/reference/auth/login

Then goto GCP Kubernetes Cluster page, Select your cluster, Click on Connect. Copy the connection string and paste it on your Google Cloud SDK Command Line on your local machine. Then try to use the kubectl commands.

Kavya
  • 105
  • 1
  • 15
  • I've already done that, but no luck, still timeout. I can run the `gcloud` commands and getting the output as well but not the kubectl one :( – Atul Singh Dec 20 '21 at 18:24