我已经在 debian minikube 上成功设置了简单的集群 Debian VM:
umen@debian12:~$ kubectl get pods
NAME READY STATUS RESTARTS AGE
hello-77c947d946-jq2s4 1/1 Running 0 45m
hello-77c947d946-wm6n2 1/1 Running 0 45m
umen@debian12:~$ minikube service list -p multinode-demo
|-------------|------------|--------------|---------------------------|
| NAMESPACE | NAME | TARGET PORT | URL |
|-------------|------------|--------------|---------------------------|
| default | hello | 80 | http://192.168.49.2:31000 |
| default | kubernetes | No node port | |
| kube-system | kube-dns | No node port | |
|-------------|------------|--------------|---------------------------|
umen@debian12:~$ curl http://192.168.49.2:31000
Hello from hello-77c947d946-wm6n2 (10.244.1.2)
正如你所看到的,所有的工作
现在在我的 Windows 主机上我尝试连接这个集群我从 Debian 服务器下载了证书
vi./kube/config_debian
apiVersion: v1
clusters:
- cluster:
certificate-authority: debian/ca.crt
extensions:
- extension:
last-update: Mon, 23 Oct 2023 08:54:23 IDT
provider: minikube.sigs.k8s.io
version: v1.31.2
name: cluster_info
server: https://192.168.49.2:8443
name: minikube
contexts:
- context:
cluster: minikube
extensions:
- extension:
last-update: Mon, 23 Oct 2023 08:54:23 IDT
provider: minikube.sigs.k8s.io
version: v1.31.2
name: context_info
namespace: default
user: minikube
name: minikube
current-context: minikube
kind: Config
preferences: {}
users:
- name: minikube
user:
client-certificate: debian/client.crt
client-key: debian/client.key
当我尝试连接时,我得到了:
$ kubectl -v=8 --kubeconfig=config_debian get pods
I1023 10:55:55.058414 16936 loader.go:372] Config loaded from file: config_debian
I1023 10:55:55.154616 16936 cert_rotation.go:137] Starting client certificate rotation controller
I1023 10:55:55.154616 16936 round_trippers.go:432] GET https://192.168.49.2:8443/api?timeout=32s
I1023 10:55:55.155136 16936 round_trippers.go:438] Request Headers:
I1023 10:55:55.155136 16936 round_trippers.go:442] Accept: application/json, */*
I1023 10:55:55.155136 16936 round_trippers.go:442] User-Agent: kubectl.exe/v1.22.0 (windows/amd64) kubernetes/c2b5237
I1023 10:56:16.186405 16936 round_trippers.go:457] Response Status: in 21031 milliseconds
I1023 10:56:16.186405 16936 round_trippers.go:460] Response Headers:
I1023 10:56:16.186405 16936 cached_discovery.go:121] skipped caching discovery info due to Get "https://192.168.49.2:8443/api?timeout=32s": dial tcp 192.168.49.2:8443: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
I1023 10:56:16.188079 16936 round_trippers.go:432] GET https://192.168.49.2:8443/api?timeout=32s
I1023 10:56:16.188079 16936 round_trippers.go:438] Request Headers:
I1023 10:56:16.188079 16936 round_trippers.go:442] Accept: application/json, */*
I1023 10:56:16.188079 16936 round_trippers.go:442] User-Agent: kubectl.exe/v1.22.0 (windows/amd64) kubernetes/c2b5237
I1023 10:56:37.192081 16936 round_trippers.go:457] Response Status: in 21003 milliseconds
I1023 10:56:37.192189 16936 round_trippers.go:460] Response Headers:
I1023 10:56:37.192189 16936 cached_discovery.go:121] skipped caching discovery info due to Get "https://192.168.49.2:8443/api?timeout=32s": dial tcp 192.168.49.2:8443: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
I1023 10:56:37.193955 16936 shortcut.go:89] Error loading discovery information: Get "https://192.168.49.2:8443/api?timeout=32s": dial tcp 192.168.49.2:8443: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
I1023 10:56:37.194510 16936 round_trippers.go:432] GET https://192.168.49.2:8443/api?timeout=32s
I1023 10:56:37.194510 16936 round_trippers.go:438] Request Headers:
I1023 10:56:37.195088 16936 round_trippers.go:442] Accept: application/json, */*
I1023 10:56:37.195088 16936 round_trippers.go:442] User-Agent: kubectl.exe/v1.22.0 (windows/amd64) kubernetes/c2b5237
问题是为什么我无法连接到远程集群
答案1
根据Github 问题 #2575,检查连接问题的原因及缓解措施,如下所述:
检查您是否在安装 Docker Toolbox(使用 VirtualBox 的旧版本)和 Docker for Windows(使用 Hyper-V)时遇到问题。删除 Docker Toolbox 并重新安装 Docker for Windows 可能有助于解决该问题。
检查服务器的资源是否不足:确保服务器有足够的资源(例如内存)来处理您发送的请求数。
从认证方面尝试以下 2 个步骤并按照文档操作minikube TLS 无需验证,这可能有助于进一步解决您的问题:
在 virtualbox 中设置从主机 8443 到 Minikube 虚拟机 8443 的端口转发
创建一个不带 TLS 验证的新上下文 minikube-vpn。