在 Kubernetes 集群上使用 etcdctl 时出错:"certificates signed by unknown authority"

Errors when using etcdctl on Kubernetes cluster: "certificates signed by unknown authority"

我有 minikube 运行ning,我正在尝试列出我的 ETCD 上的密钥。

我从 github 下载了最新的 etcdctl 客户端:
https://github.com/etcd-io/etcd/releases/download/v3.3.18/etcd-v3.3.18-linux-amd64.tar.gz

我尝试 运行 使用来自 /home/myuser/.minikube/certs 的证书:

./etcdctl --ca-file /home/myuser/.minikube/certs/ca.pem 
          --key-file /home/myuser/.minikube/certs/key.pem 
          --cert-file /home/myuser/.minikube/certs/cert.pem  
          --endpoints=https://10.240.0.23:2379 get / 

我收到一个错误:

Error: client: etcd cluster is unavailable or misconfigured; error #0: x509: certificate signed by unknown authority

error #0: x509: certificate signed by unknown authority

我是否使用了正确的证书?

我尝试了不同的证书:

./etcdctl --ca-file /var/lib/minikube/certs/ca.crt 
          --key-file /var/lib/minikube/certs/apiserver-etcd-client.key 
          --cert-file /var/lib/minikube/certs/apiserver-etcd-client.crt 
          --endpoints=https://10.240.0.23:2379 get /   

我收到了与之前相同的错误。

知道问题出在哪里吗?

尝试执行以下命令: $ cat /etc/etcd.env 列出 CA、CERT、KEY 目录(实际路径)。

TLS 设置

ETCD_TRUSTED_CA_FILE=/etc/ssl/etcd/ssl/ca.pem
ETCD_CERT_FILE=/etc/ssl/etcd/ssl/member-k8s-m1.pem
ETCD_KEY_FILE=/etc/ssl/etcd/ssl/member-k8s-m1-key.pem
ETCD_CLIENT_CERT_AUTH=true

那么您就可以正确使用证书了。

然后再次运行命令:

./etcdctl --endpoints https://x.x.x.x:2379 
          --ca-file=/etc/ssl/etcd/ssl/ca.pem 
          --cert-file=/etc/ssl/etcd/ssl/member-k8s-m1.pem 
          --key-file=/etc/ssl/etcd/ssl/member-k8s-m1-key.pem

您可以在此处找到更多信息:etcd-certificates

我需要在命令前使用 ETCDCTL_API=3
我从这个 Github.
看到了它在 Kubernetes 中的艰难使用 证书的位置在:/etc/kubernetes/pki/etcd

命令应该像这样工作:

ETCDCTL_API=3 ./etcdctl --endpoints=https://172.17.0.64:2379 \
                        --cacert=/etc/kubernetes/pki/etcd/ca.crt \
                        --cert=/etc/kubernetes/pki/etcd/server.crt \
                        --key=/etc/kubernetes/pki/etcd/server.key get / --prefix

我测试了它,它对我有用。

对于 minikube,etcd 证书的正确路径是:/var/lib/minikube/certs/etcd/ 所以命令将是这样的:

# kubectl -n kube-system exec -it etcd-minikube -- sh -c "ETCDCTL_API=3 ETCDCTL_CACERT=/var/lib/minikube/certs/etcd/ca.crt ETCDCTL_CERT=/var/lib/minikube/certs/etcd/server.crt ETCDCTL_KEY=/var/lib/minikube/certs/etcd/server.key etcdctl endpoint health"

如果你想从 host/outside 它的容器中转储所有带前缀的 etcd 条目,你也可以发出(此处用于 minikube/local 测试):

kubectl exec -it \
  -n kube-system etcd-minikube \
  -- sh -c 'ETCDCTL_CACERT=/var/lib/minikube/certs/etcd/ca.crt \
    ETCDCTL_CERT=/var/lib/minikube/certs/etcd/server.crt \
    ETCDCTL_KEY=/var/lib/minikube/certs/etcd/server.key \
    ETCDCTL_API=3  \
    etcdctl \
      get \
      --prefix=true /'