奇怪的是,我无法通过Kubectl从本地(Mac)连接到GKE集群,但我可以从Google云外壳连接吗?我已经获取了K8s文件,我可以看到kubeconfig文件,但我仍然需要超时。有什么建议可能是错的吗?
$ 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
发布于 2021-12-21 12:23:34
在分析了集群的所有配置之后,我发现“控制平面授权网络”已被启用,这实际上是“使控制平面授权网络能够阻止不可信的非GCP源IP通过HTTPS访问Kubernetes控制平面”。我的本地IP显然不是GCP IP。
一旦我禁用了它,我可以从我的本地系统连接。
发布于 2021-12-20 21:54:30
发布于 2021-12-20 22:08:06
注释您不需要用
gcloud
安装kubectl
;任何有效的kubectl
都可以。
您可以确保kubectl
在配置文件的预期位置上使用KUBECONFIG
作为前缀,例如:
KUBECONFIG=/path/to/.kube/config kubectl get nodes
配置文件是否包含GKE集群的正确条目?
apiVersion: v1
clusters:
- cluster:
certificate-authority-data: LS0tLS1C...
server: https://${IP}
name: gke_${PROJECT}_${LOCATION}_${NAME}
contexts:
- context:
cluster: gke_${PROJECT}_${LOCATION}_${NAME}
user: gke_${PROJECT}_${LOCATION}_${NAME}
name: gke_${PROJECT}_${LOCATION}_${NAME}
current-context: gke_${PROJECT}_${LOCATION}_${NAME}
kind: Config
preferences: {}
users:
- name: gke_${PROJECT}_${LOCATION}_${NAME}
user:
auth-provider:
config:
access-token: ya29...
cmd-args: config config-helper --format=json
cmd-path: /path/to/gcloud
expiry: "2021-12-20T00:00:00Z"
expiry-key: '{.credential.token_expiry}'
token-key: '{.credential.access_token}'
name: gcp
适当替换gke_${PROJECT}_${LOCATION}_${NAME}
值的位置。
current-context
设置好了吗?
您能从Mac中平分集群的IP (${IP}
)吗?
https://stackoverflow.com/questions/70426132
复制相似问题