Kubectl 命令仅适用于 minikube

Kubectl commands only working with minikube

为什么当我使用 minikube 时,我的所有 kubectl 命令都能正常工作,例如kubectl get nodes。但是我 停止 minikube 并尝试使用 k3d 的那一刻。

  1. 使用 choco install k3d
  2. 安装 k3d
  3. 在k3d中创建集群
  4. 将上下文设置为创建的集群

不知何故,kubectl get nodeskubectl get pods 等命令不起作用,return

Unable to connect to the server: dial tcp 145.93.104.168:61199: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or e
stablished connection failed because connected host has failed to respond.

为什么我 运行 kubectl 命令不能正确地与 k3d 一起使用?

Kubectl 配置视图:

apiVersion: v1
clusters:
- cluster:
    certificate-authority-data: DATA+OMITTED
    server: https://host.docker.internal:61199
  name: k3d-kwetter-cluster
- cluster:
    certificate-authority: C:\Users\ZRC\.minikube\ca.crt
    extensions:
    - extension:
        last-update: Thu, 07 Apr 2022 11:25:37 CEST
        provider: minikube.sigs.k8s.io
        version: v1.25.2
      name: cluster_info
    server: https://127.0.0.1:65229
  name: minikube
contexts:
- context:
    cluster: k3d-kwetter-cluster
    user: admin@k3d-kwetter-cluster
  name: k3d-kwetter-cluster
- context:
    cluster: minikube
    extensions:
    - extension:
        last-update: Thu, 07 Apr 2022 11:25:37 CEST
        provider: minikube.sigs.k8s.io
        version: v1.25.2
      name: context_info
    namespace: default
    user: minikube
  name: minikube
current-context: k3d-kwetter-cluster
kind: Config
preferences: {}
users:
- name: admin@k3d-kwetter-cluster
  user:
    client-certificate-data: REDACTED
    client-key-data: REDACTED
- name: minikube
  user:
    client-certificate: C:\Users\ZRC\.minikube\profiles\minikube\client.crt
    client-key: C:\Users\ZRC\.minikube\profiles\minikube\client.key

额外的上下文:我尝试不使用 minikube,因为我根本无法从外部访问我部署的应用程序(NodePort,入口,端口转发......我尝试了很多东西,但那些就是没有工作。但现在 k3d 也不工作了)

在 Docker 桌面中,转到设置 > Kubernetes > 启用 Kubernetes 设置为 true。