k3s 集群使用 helm 安装 vault 时出现 Error

error 复现

当我在 k3s 集群的 master 节点执行 helm 命令安装 vault 时,报错产生。 具体信息为:Error: Kubernetes cluster unreachable: Get "http://localhost:8080/version?timeout=32s": dial tcp 127.0.0.1:8080: connect: connection refused

TroubleShooting

在经过面向 google 查找之后,找到了一篇博文,介绍了该问题的解决方法。 helm 3 中取消了 tiller 的使用,通过直接与 apiserver 进行通信来完成交互。而 helm 默认读取的配置文件路径 在 .kube/config,而 k3s 的 config 文件存放路径则是 /etc/rancher/k3s/k3s.yaml

解决方案

  1. 直接使用 export 声明 kubeconfig 文件路径,或是 helm 执行命令时加入 kubeconfig 路径
  2. 在配置文件 /etc/profile 中声明 kubeconfig 文件的路径,一劳永逸的解决。
1
2
3
4
5
6
7
8
9
# 方案一

export KUBECONFIG=/etc/rancher/k3s/k3s.yaml
# or
helm install options --kubeconfig /etc/rancher/k3s/k3s.yaml

# 方案二
sudo echo "export KUBECONFIG=/etc/rancher/k3s/k3s.yaml" >> /etc/profile
source /etc/profile
Built with Hugo
Theme Stack designed by Jimmy