helm: x509: 由未知授权机构签署的证书

helm: x509: certificate signed by unknown authority

我正在使用 Kubernetes,我最近更新了我在 kubeconfig 中使用的管理员证书。但是,在我这样做之后,所有 helm 命令都因此失败:

Error: Get https://cluster.mysite.com/api/v1/namespaces/kube-system/pods?labelSelector=app%3Dhelm%2Cname%3Dtiller: x509: certificate signed by unknown authority

kubectl 按预期工作:

$ kubectl get nodes
NAME                                           STATUS    ROLES     AGE       VERSION
ip-10-1-0-34.eu-central-1.compute.internal     Ready     master    42d       v1.7.10+coreos.0
ip-10-1-1-51.eu-central-1.compute.internal     Ready     master    42d       v1.7.10+coreos.0
ip-10-1-10-120.eu-central-1.compute.internal   Ready     <none>    42d       v1.7.10+coreos.0
ip-10-1-10-135.eu-central-1.compute.internal   Ready     <none>    27d       v1.7.10+coreos.0
ip-10-1-11-71.eu-central-1.compute.internal    Ready     <none>    42d       v1.7.10+coreos.0
ip-10-1-12-199.eu-central-1.compute.internal   Ready     <none>    8d        v1.7.10+coreos.0
ip-10-1-2-110.eu-central-1.compute.internal    Ready     master    42d       v1.7.10+coreos.0

据我所知,helm 应该使用与 kubectl 相同的证书,这让我很好奇 kubectl 是如何工作的,但是helm 没有?

这是一个生产集群,内部版本通过 helm 图表处理,因此解决它势在必行。

如有任何提示,我们将不胜感激。

作为解决方法,您可以尝试禁用证书验证。 Helm 使用 kube 配置文件(默认 ~/.kube/config)。您可以为 cluster 部分添加 insecure-skip-tls-verify: true

clusters:
- cluster:
    server: https://cluster.mysite.com
    insecure-skip-tls-verify: true
  name: default

您是否已尝试重新安装 helm/tiller?

kubectl delete deployment tiller-deploy --namespace kube-system
helm init

同时检查您是否在集群配置中配置了无效的证书。

在我的例子中,错误是由来自 Helm 存储库的不受信任的证书引起的。 下载证书并使用 --ca-file 选项指定它解决了问题(至少在 Helm 版本 3 中)。

helm repo add --ca-file /path/to/certificate.crt repoName https://example/repository

--ca-file string, verify certificates of HTTPS-enabled servers using this CA bundle

尽管使用 --ca-file 添加 repo 可以做到这一点,但当它尝试使用下面发布的命令从该 repo 下载时,我仍然得到了 x509: 由未知权威机构签署的证书

helm dependency update helm/myStuff
Hang tight while we grab the latest from your chart repositories...
...Successfully got an update from the "myRepo" chart repository
Update Complete. ⎈Happy Helming!⎈
Saving 18 charts
Downloading myService from repo https://myCharts.me/
Save error occurred:  could not download https://myCharts.me/stuff.tgz ...
x509: certificate signed by unknown authority
Deleting newly downloaded charts, restoring pre-update state

除了使用 --ca-file 添加 repo 之外,我需要做的是下载存储库证书并将其安装为当前用户:

将所有证书放在以下存储中:受信任的根证书颁发机构:

安装证书后还需要重启电脑。重新启动后,当您打开浏览器并粘贴 repo URL 时,它应该会在不发出警告并信任该站点的情况下连接(这样您就知道您已成功安装证书)。

您可以继续执行 运行 命令,这次应该选择证书。

helm dependency update helm/myStuff
....
Saving 18 charts
Downloading service1 from repo https://myCharts.me/
Downloading service2 from repo https://myCharts.me/
....

在我的例子中,我是 运行 一个 self-manage 并且配置文件也是容器 ca-file,所以上面的答案下面是错误

Error: Kubernetes cluster unreachable: Get "https://XX.XX.85.154:6443/version?timeout=32s": x509: certificate is valid for 10.96.0.1, 172.31.25.161, not XX.XX.85.154

我的配置是

- cluster:
    certificate-authority-data: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    server: https://54.176.85.154:6443
    insecure-skip-tls-verify: true

所以我不得不删除 certificate-authority-data

- cluster:
    server: https://54.176.85.154:6443
    insecure-skip-tls-verify: true

将 -cluster 下面的行添加到 /home/centos/.kube/config 文件解决了我的问题

insecure-skip-tls-verify: true

解决了我的问题。

我的配置文件现在看起来像这样。

apiVersion: v1
clusters:
- cluster:
    certificate-authority: /home/centos/.minikube/ca.crt
    extensions:
    - extension:
        last-update: Tue, 02 Nov 2021 20:51:44 EDT
        provider: minikube.sigs.k8s.io
        version: v1.23.2
      name: cluster_info
    server: https://192.168.49.2:8443
    insecure-skip-tls-verify: true
  name: minikube
contexts:

使用--insecure-skip-tls-verify通过命令行跳过tls验证

helm repo add stable --insecure-skip-tls-verify https://charts.helm.sh/stable

就我而言,在我升级到 helm v.3.9.0 后,它是旧版本的 helm(在我的情况下是 v.3.6.3)brew upgrade helm 一切都恢复正常了。