发布时间: 2024-10-24 文章作者: myluzh 分类名称: Kubernetes 朗读文章
curl: (35) error:14094412:SSL routines:ssl3_read_bytes:sslv3 alert bad certificate这是因为 etcd 启用了 SSL 双向认证,服务端要求客户端提供有效的证书和私钥进行身份验证。
curl --cert /etc/kubernetes/ssl/kube-etcd-172-30-233-87.pem \ --key /etc/kubernetes/ssl/kube-etcd-172-30-233-87-key.pem \ --cacert /etc/kubernetes/ssl/kube-ca.pem \ https://172.30.233.87:2379/metrics如果你想跳过 CA 验证(不检查服务端的证书),可以使用 -k 选项来忽略此步骤,但仍需要提供客户端证书和私钥:
curl --cert /etc/kubernetes/ssl/kube-etcd-172-30-233-87.pem \ --key /etc/kubernetes/ssl/kube-etcd-172-30-233-87-key.pem \ -k https://172.30.233.87:2379/metrics
# 导入etcd证书 kubectl -n monitoring create secret generic etcd-certs \ --from-file=healthcheck-client.crt=/etc/kubernetes/ssl/kube-etcd-172-30-233-87.pem \ --from-file=healthcheck-client.key=/etc/kubernetes/ssl/kube-etcd-172-30-233-87-key.pem \ --from-file=ca.crt=/etc/kubernetes/ssl/kube-ca.pem2、manifests/prometheus-prometheus.yaml配置文件中添加secrets属性,用于将之前创建的etcd-certs Secret挂载到Prometheus的Pod中。
# 添加secrets属性 nodeSelector: beta.kubernetes.io/os: linux replicas: 2 secrets: - etcd-certs3、用更新后的manifests/prometheus-prometheus.yaml文件重建Prometheus实例,确保secrets属性生效,使Prometheus可以使用etcd-certs Secret进行 SSL认证与etcd 通信。
# 重启 prometheus-operator kubectl -n monitoring rollout restart deployment prometheus-operator # 重建 prometheus kubectl replace -f prometheus-prometheus.yaml4、测试etcd证书已经挂载到Prometheus里面。
kubectl exec -it prometheus-k8s-0 /bin/sh -n monitoring /prometheus $ ls /etc/prometheus/secrets/etcd-certs ca.crt healthcheck-client.crt healthcheck-client.key5、创建了一个名为etcd-monitoring的Service和Endpoints,将流量转发到外部IP172.30.233.87的2379端口。
# Service的名字和Endpoints的名字必须相同,以便系统能够自动匹配和转发流量。 apiVersion: v1 kind: Endpoints metadata: name: etcd-monitoring namespace: kube-system subsets: - addresses: - ip: 172.30.233.87 ports: - name: etcd2379 port: 2379 --- apiVersion: v1 kind: Service metadata: name: etcd-monitoring # 要跟上面Endpoint的name一致 namespace: kube-system labels: app.kubernetes.io/name: etcd spec: ports: - name: etcd2379 port: 2379 targetPort: 23796、创建ServiceMonitor,通过namespaceSelector选择到kube-system命名空间,标签为app.kubernetes.io/name: etcd ,要跟上面SVC的labels一样。
# etcd-serviceMonitor.yaml apiVersion: monitoring.coreos.com/v1 kind: ServiceMonitor metadata: name: etcd namespace: monitoring spec: endpoints: - interval: 30s port: etcd2379 scheme: https tlsConfig: caFile: /etc/prometheus/secrets/etcd-certs/ca.crt # prometheus挂载证书的所在路径 certFile: /etc/prometheus/secrets/etcd-certs/healthcheck-client.crt keyFile: /etc/prometheus/secrets/etcd-certs/healthcheck-client.key insecureSkipVerify: true jobLabel: k8s-app selector: matchLabels: app.kubernetes.io/name: etcd # 与上方etcd-monnitoring svc 标签匹配 namespaceSelector: matchNames: - kube-system # etcd-monitoring svc所在的命名空间
标签: ssl service Prometheus etcd 2379 monitoring 有metrics接口
发表评论