Helm 3: 连接到本地 Kubernetes 时出现 x509 错误

Helm 3: x509 error when connecting to local Kubernetes

我是 K8s 的完美 菜鸟。我使用 snap 安装了 microk8s and Helm 以在本地进行试验。我想知道我现在的问题是不是因为使用了snap(我理解的目的是封装)

环境

Ubuntu 20.04LTS

helm version                                                                            
version.BuildInfo{Version:"v3.2.4", GitCommit:"0ad800ef43d3b826f31a5ad8dfbb4fe05d143688", GitTreeState:"clean", GoVersion:"go1.13.12"}
kubectl version     
Client Version: version.Info{Major:"1", Minor:"18+", GitVersion:"v1.18.4-1+6f17be3f1fd54a", GitCommit:"6f17be3f1fd54a88681869d1cf8bedd5a2174504", GitTreeState:"clean", BuildDate:"2020-06-23T21:16:24Z", GoVersion:"go1.14.4", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"18+", GitVersion:"v1.18.4-1+6f17be3f1fd54a", GitCommit:"6f17be3f1fd54a88681869d1cf8bedd5a2174504", GitTreeState:"clean", BuildDate:"2020-06-23T21:17:52Z", GoVersion:"go1.14.4", Compiler:"gc", Platform:"linux/amd64"}
kubectl config get-contexts                                                             
CURRENT   NAME       CLUSTER            AUTHINFO   NAMESPACE
*         microk8s   microk8s-cluster   admin      

Post 安装设置

microk8s enable helm3

Kubernetes 启动并且 运行

kubectl cluster-info 
Kubernetes master is running at https://127.0.0.1:16443
CoreDNS is running at https://127.0.0.1:16443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

连接 helmmicrok8s 时出现问题

helm ls --kube-token ~/token --kube-apiserver https://127.0.0.1:16443
Error: Kubernetes cluster unreachable: Get https://127.0.0.1:16443/version?timeout=32s: x509: certificate signed by unknown authority

我怎么知道helm

根据我的阅读,我可以通过使用 --kubeconfig.

指向 kube 的配置来解决这个问题
helm ls --kube-token ~/token --kube-apiserver https://127.0.0.1:16443 --kubeconfig /path/to/kubernetes/config

microk8ssnap 一起安装的情况下,我不太确定这个 conf 文件 是什么,也不知道在哪里可以找到它。

Helm 在此路径 $HOME/.kube/config.

中查找 kubeconfig

请运行这个指令

microk8s.kubectl config view --raw > $HOME/.kube/config

这会将配置保存在您目录中所需的路径中并且应该可以工作

参考Linkhere

请尝试使用以下命令导出 kubeconfig 文件: 导出 KUBECONFIG=/var/snap/microk8s/current/credentials/client.config

如果你碰巧在 docker 桌面上使用 WSL,在 docker 桌面上使用 k8s 运行,但在 WSL 中使用 helm 运行 Tarun 提供的非常相似的命令也可以。

假设您是运行 Windows 版本的 kubectl

➜  which kubectl.exe 
➜    /mnt/c/Program Files/Docker/Docker/resources/bin/kubectl.exe
➜  which kubectl 
➜    kubectl: aliased to /mnt/c/Program\ Files/Docker/Docker/resources/bin/kubectl.exe


➜  kubectl config view --raw > $HOME/.kube/config